using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace TeleWave.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class DropLegacyRotation : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropTable(name: "ChannelAd");

            migrationBuilder.DropTable(name: "ChannelShowHour");

            migrationBuilder.DropTable(name: "OverrideShow");

            migrationBuilder.DropTable(name: "ChannelShow");

            migrationBuilder.DropTable(name: "ProgrammingOverride");

            migrationBuilder.DropColumn(name: "AdInsertion", table: "Channels");

            migrationBuilder.DropColumn(name: "AdsPerBreak", table: "Channels");

            migrationBuilder.DropColumn(name: "NextAdIndex", table: "Channels");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "AdInsertion",
                table: "Channels",
                type: "integer",
                nullable: false,
                defaultValue: 0
            );

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

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

            migrationBuilder.CreateTable(
                name: "ChannelAd",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ChannelId = table.Column<Guid>(type: "uuid", nullable: false),
                    MediaAssetId = table.Column<Guid>(type: "uuid", nullable: false),
                    Position = table.Column<int>(type: "integer", nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChannelAd", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ChannelAd_Channels_ChannelId",
                        column: x => x.ChannelId,
                        principalTable: "Channels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade
                    );
                }
            );

            migrationBuilder.CreateTable(
                name: "ChannelShow",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    BlockMode = table.Column<int>(type: "integer", nullable: false),
                    BlockValue = table.Column<int>(type: "integer", nullable: false),
                    ChannelId = table.Column<Guid>(type: "uuid", nullable: false),
                    IsEnabled = table.Column<bool>(type: "boolean", nullable: false),
                    NextEpisodeIndex = table.Column<int>(type: "integer", nullable: false),
                    PreferredWeightMultiplier = table.Column<int>(
                        type: "integer",
                        nullable: false,
                        defaultValue: 3
                    ),
                    ShowId = table.Column<Guid>(type: "uuid", nullable: false),
                    Weight = table.Column<int>(type: "integer", nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChannelShow", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ChannelShow_Channels_ChannelId",
                        column: x => x.ChannelId,
                        principalTable: "Channels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade
                    );
                }
            );

            migrationBuilder.CreateTable(
                name: "ProgrammingOverride",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ChannelId = table.Column<Guid>(type: "uuid", nullable: false),
                    DayOfWeek = table.Column<int>(type: "integer", nullable: true),
                    EndMinute = table.Column<int>(type: "integer", nullable: true),
                    EndsAtUtc = table.Column<DateTimeOffset>(
                        type: "timestamp with time zone",
                        nullable: true
                    ),
                    Mode = table.Column<int>(type: "integer", nullable: false),
                    Recurrence = table.Column<int>(type: "integer", nullable: false),
                    StartMinute = table.Column<int>(type: "integer", nullable: true),
                    StartsAtUtc = table.Column<DateTimeOffset>(
                        type: "timestamp with time zone",
                        nullable: true
                    ),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ProgrammingOverride", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ProgrammingOverride_Channels_ChannelId",
                        column: x => x.ChannelId,
                        principalTable: "Channels",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade
                    );
                }
            );

            migrationBuilder.CreateTable(
                name: "ChannelShowHour",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ChannelShowId = table.Column<Guid>(type: "uuid", nullable: false),
                    EndHour = table.Column<int>(type: "integer", nullable: false),
                    StartHour = table.Column<int>(type: "integer", nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChannelShowHour", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ChannelShowHour_ChannelShow_ChannelShowId",
                        column: x => x.ChannelShowId,
                        principalTable: "ChannelShow",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade
                    );
                }
            );

            migrationBuilder.CreateTable(
                name: "OverrideShow",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ProgrammingOverrideId = table.Column<Guid>(type: "uuid", nullable: false),
                    ShowId = table.Column<Guid>(type: "uuid", nullable: false),
                    Weight = table.Column<int>(type: "integer", nullable: false),
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_OverrideShow", x => x.Id);
                    table.ForeignKey(
                        name: "FK_OverrideShow_ProgrammingOverride_ProgrammingOverrideId",
                        column: x => x.ProgrammingOverrideId,
                        principalTable: "ProgrammingOverride",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade
                    );
                }
            );

            migrationBuilder.CreateIndex(
                name: "IX_ChannelAd_ChannelId_Position",
                table: "ChannelAd",
                columns: new[] { "ChannelId", "Position" }
            );

            migrationBuilder.CreateIndex(
                name: "IX_ChannelShow_ChannelId_ShowId",
                table: "ChannelShow",
                columns: new[] { "ChannelId", "ShowId" }
            );

            migrationBuilder.CreateIndex(
                name: "IX_ChannelShowHour_ChannelShowId",
                table: "ChannelShowHour",
                column: "ChannelShowId"
            );

            migrationBuilder.CreateIndex(
                name: "IX_OverrideShow_ProgrammingOverrideId",
                table: "OverrideShow",
                column: "ProgrammingOverrideId"
            );

            migrationBuilder.CreateIndex(
                name: "IX_ProgrammingOverride_ChannelId_StartsAtUtc_EndsAtUtc",
                table: "ProgrammingOverride",
                columns: new[] { "ChannelId", "StartsAtUtc", "EndsAtUtc" }
            );
        }
    }
}
