using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblJobAutoControlAndRel : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "JobAutoControls",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    DateModified = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
                    ApplicationInWorkId = table.Column<Guid>(type: "uuid", nullable: false),
                    CreateNew = table.Column<bool>(type: "boolean", nullable: false),
                    Deactivate = table.Column<bool>(type: "boolean", nullable: false),
                    Activate = table.Column<bool>(type: "boolean", nullable: false),
                    OnTemplateIsActive = table.Column<bool>(type: "boolean", nullable: false),
                    OnScheduleIsActive = table.Column<bool>(type: "boolean", nullable: false),
                    OffTemplateIsActive = table.Column<bool>(type: "boolean", nullable: false),
                    OffScheduleIsActive = table.Column<bool>(type: "boolean", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_JobAutoControls", x => x.Id);
                    table.ForeignKey(
                        name: "FK_JobAutoControls_ApplicationsInWorks_ApplicationInWorkId",
                        column: x => x.ApplicationInWorkId,
                        principalTable: "ApplicationsInWorks",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "JobAutoControlInEkStatus",
                columns: table => new
                {
                    JobAutoControlId = table.Column<Guid>(type: "uuid", nullable: false),
                    EkStatusCode = table.Column<int>(type: "integer", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_JobAutoControlInEkStatus", x => new { x.JobAutoControlId, x.EkStatusCode });
                    table.ForeignKey(
                        name: "FK_JobAutoControlInEkStatus_EkStatuses_EkStatusCode",
                        column: x => x.EkStatusCode,
                        principalTable: "EkStatuses",
                        principalColumn: "Code",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_JobAutoControlInEkStatus_JobAutoControls_JobAutoControlId",
                        column: x => x.JobAutoControlId,
                        principalTable: "JobAutoControls",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "JobEkMasks",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DateCreated = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    JobAutoControlId = table.Column<Guid>(type: "uuid", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_JobEkMasks", x => x.Id);
                    table.ForeignKey(
                        name: "FK_JobEkMasks_JobAutoControls_JobAutoControlId",
                        column: x => x.JobAutoControlId,
                        principalTable: "JobAutoControls",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_JobAutoControlInEkStatus_EkStatusCode",
                table: "JobAutoControlInEkStatus",
                column: "EkStatusCode");

            migrationBuilder.CreateIndex(
                name: "IX_JobAutoControls_ApplicationInWorkId",
                table: "JobAutoControls",
                column: "ApplicationInWorkId",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_JobEkMasks_JobAutoControlId",
                table: "JobEkMasks",
                column: "JobAutoControlId");
        }

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

            migrationBuilder.DropTable(
                name: "JobEkMasks");

            migrationBuilder.DropTable(
                name: "JobAutoControls");
        }
    }
}
