using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

#pragma warning disable CA1814 // Prefer jagged arrays over multidimensional

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblTemplateStatusType : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "IsUnused",
                table: "Templates");

            migrationBuilder.AddColumn<int>(
                name: "StatusTypeId",
                table: "Templates",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "StatusTypeId",
                table: "TemplateHistories",
                type: "integer",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.CreateTable(
                name: "TemplateStatusTypes",
                columns: table => new
                {
                    Id = table.Column<int>(type: "integer", nullable: false),
                    Name = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_TemplateStatusTypes", x => x.Id);
                },
                comment: "Таблица описания критериев выборки аттрибутов ЭК");

            migrationBuilder.InsertData(
                table: "TemplateStatusTypes",
                columns: new[] { "Id", "Description", "Name" },
                values: new object[,]
                {
                    { 0, "В работе", "Used" },
                    { 1, "Не используется", "Unused" },
                    { 2, "Обновляется", "Updating" }
                });

            migrationBuilder.CreateIndex(
                name: "IX_Templates_StatusTypeId",
                table: "Templates",
                column: "StatusTypeId");

            migrationBuilder.AddForeignKey(
                name: "FK_Templates_TemplateStatusTypes_StatusTypeId",
                table: "Templates",
                column: "StatusTypeId",
                principalTable: "TemplateStatusTypes",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_Templates_TemplateStatusTypes_StatusTypeId",
                table: "Templates");

            migrationBuilder.DropTable(
                name: "TemplateStatusTypes");

            migrationBuilder.DropIndex(
                name: "IX_Templates_StatusTypeId",
                table: "Templates");

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

            migrationBuilder.DropColumn(
                name: "StatusTypeId",
                table: "TemplateHistories");

            migrationBuilder.AddColumn<bool>(
                name: "IsUnused",
                table: "Templates",
                type: "boolean",
                nullable: false,
                defaultValue: false);
        }
    }
}
