using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblTemplateHistory : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "InitiatorComment",
                table: "Templates",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "InitiatorIp",
                table: "Templates",
                type: "text",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "InitiatorParrComponentId",
                table: "Templates",
                type: "integer",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "TemplateHistories",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ParentId = table.Column<Guid>(type: "uuid", nullable: false),
                    DateAddedToHistory = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    InitiatorIp = table.Column<string>(type: "text", nullable: true),
                    InitiatorParrComponentId = table.Column<int>(type: "integer", nullable: true),
                    InitiatorComment = table.Column<string>(type: "text", nullable: true),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    Name = table.Column<string>(type: "text", nullable: false),
                    IsActiveTemplate = table.Column<bool>(type: "boolean", nullable: false),
                    IsActiveSchedule = table.Column<bool>(type: "boolean", nullable: false),
                    LastRun = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    NextRun = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TemplateHistories", x => x.Id);
                    table.ForeignKey(
                        name: "FK_TemplateHistories_Templates_ParentId",
                        column: x => x.ParentId,
                        principalTable: "Templates",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_TemplateHistories_ParentId",
                table: "TemplateHistories",
                column: "ParentId");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(
                name: "TemplateHistories");

            migrationBuilder.DropColumn(
                name: "InitiatorComment",
                table: "Templates");

            migrationBuilder.DropColumn(
                name: "InitiatorIp",
                table: "Templates");

            migrationBuilder.DropColumn(
                name: "InitiatorParrComponentId",
                table: "Templates");
        }
    }
}
