using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

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

namespace PARR.DAL.Migrations
{
    /// <inheritdoc />
    public partial class tblDistributionPerioadAddTypes : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "Duration",
                table: "DistributionPeriods",
                type: "text",
                nullable: false,
                oldClrType: typeof(TimeSpan),
                oldType: "interval");

            migrationBuilder.AddColumn<string>(
                name: "Type",
                table: "DistributionPeriods",
                type: "text",
                nullable: false,
                defaultValue: "");

            migrationBuilder.CreateTable(
                name: "DistributionPeriodTypes",
                columns: table => new
                {
                    Type = table.Column<string>(type: "text", nullable: false),
                    Description = table.Column<string>(type: "text", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DistributionPeriodTypes", x => x.Type);
                });

            migrationBuilder.InsertData(
                table: "DistributionPeriodTypes",
                columns: new[] { "Type", "Description" },
                values: new object[,]
                {
                    { "Day", "День" },
                    { "Month", "Месяц" },
                    { "TimeSpan", "TimeSpan" },
                    { "Year", "Год" }
                });

            migrationBuilder.UpdateData(
                table: "DistributionPeriods",
                keyColumn: "Id",
                keyValue: new Guid("0ad2dfdb-3833-46d9-979a-c408b7eadc6c"),
                columns: new[] { "Duration", "Type" },
                values: new object[] { "90", "Day" });

            migrationBuilder.UpdateData(
                table: "DistributionPeriods",
                keyColumn: "Id",
                keyValue: new Guid("3a7341a8-085c-461c-babc-6b78dd5d2c67"),
                columns: new[] { "Duration", "Type" },
                values: new object[] { "1", "Month" });

            migrationBuilder.CreateIndex(
                name: "IX_DistributionPeriods_Type",
                table: "DistributionPeriods",
                column: "Type");

            migrationBuilder.AddForeignKey(
                name: "FK_DistributionPeriods_DistributionPeriodTypes_Type",
                table: "DistributionPeriods",
                column: "Type",
                principalTable: "DistributionPeriodTypes",
                principalColumn: "Type",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropTable(
                name: "DistributionPeriodTypes");

            migrationBuilder.DropIndex(
                name: "IX_DistributionPeriods_Type",
                table: "DistributionPeriods");

            migrationBuilder.DropColumn(
                name: "Type",
                table: "DistributionPeriods");

            migrationBuilder.AlterColumn<TimeSpan>(
                name: "Duration",
                table: "DistributionPeriods",
                type: "interval",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "text");

            migrationBuilder.UpdateData(
                table: "DistributionPeriods",
                keyColumn: "Id",
                keyValue: new Guid("0ad2dfdb-3833-46d9-979a-c408b7eadc6c"),
                column: "Duration",
                value: new TimeSpan(90, 0, 0, 0, 0));

            migrationBuilder.UpdateData(
                table: "DistributionPeriods",
                keyColumn: "Id",
                keyValue: new Guid("3a7341a8-085c-461c-babc-6b78dd5d2c67"),
                column: "Duration",
                value: new TimeSpan(28, 0, 0, 0, 0));
        }
    }
}
