using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace ErsatzTV.Infrastructure.MySql.Migrations
{
    /// <inheritdoc />
    public partial class AddChannelTemplates : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "ChannelTemplate",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("MySql:ValueGenerationStrategy", MySqlValueGenerationStrategy.IdentityColumn),
                    Name = table.Column<string>(type: "varchar(50)", maxLength: 50, nullable: false, collation: "utf8mb4_general_ci")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    Description = table.Column<string>(type: "varchar(500)", maxLength: 500, nullable: false, defaultValue: "")
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    IsSystem = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    FFmpegProfileId = table.Column<int>(type: "int", nullable: false),
                    WatermarkId = table.Column<int>(type: "int", nullable: true),
                    FallbackFillerId = table.Column<int>(type: "int", nullable: true),
                    PreRollFillerId = table.Column<int>(type: "int", nullable: true),
                    MidRollFillerId = table.Column<int>(type: "int", nullable: true),
                    PostRollFillerId = table.Column<int>(type: "int", nullable: true),
                    StreamSelectorMode = table.Column<int>(type: "int", nullable: false),
                    StreamSelector = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PreferredAudioLanguageCode = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PreferredAudioTitle = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    PlayoutSource = table.Column<int>(type: "int", nullable: false),
                    PlayoutMode = table.Column<int>(type: "int", nullable: false),
                    StreamingMode = table.Column<int>(type: "int", nullable: false),
                    PreferredSubtitleLanguageCode = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SubtitleMode = table.Column<int>(type: "int", nullable: false),
                    MusicVideoCreditsMode = table.Column<int>(type: "int", nullable: false),
                    MusicVideoCreditsTemplate = table.Column<string>(type: "longtext", nullable: true)
                        .Annotation("MySql:CharSet", "utf8mb4"),
                    SongVideoMode = table.Column<int>(type: "int", nullable: false),
                    TranscodeMode = table.Column<int>(type: "int", nullable: false),
                    IdleBehavior = table.Column<int>(type: "int", nullable: false),
                    ShuffleScheduleItems = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    RandomStartPoint = table.Column<bool>(type: "tinyint(1)", nullable: false),
                    FixedStartTimeBehavior = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ChannelTemplate", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ChannelTemplate_ChannelWatermark_WatermarkId",
                        column: x => x.WatermarkId,
                        principalTable: "ChannelWatermark",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_ChannelTemplate_FFmpegProfile_FFmpegProfileId",
                        column: x => x.FFmpegProfileId,
                        principalTable: "FFmpegProfile",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_ChannelTemplate_FillerPreset_FallbackFillerId",
                        column: x => x.FallbackFillerId,
                        principalTable: "FillerPreset",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_ChannelTemplate_FillerPreset_MidRollFillerId",
                        column: x => x.MidRollFillerId,
                        principalTable: "FillerPreset",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_ChannelTemplate_FillerPreset_PostRollFillerId",
                        column: x => x.PostRollFillerId,
                        principalTable: "FillerPreset",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                    table.ForeignKey(
                        name: "FK_ChannelTemplate_FillerPreset_PreRollFillerId",
                        column: x => x.PreRollFillerId,
                        principalTable: "FillerPreset",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.SetNull);
                })
                .Annotation("MySql:CharSet", "utf8mb4");

            migrationBuilder.CreateIndex(
                name: "IX_ChannelTemplate_FallbackFillerId",
                table: "ChannelTemplate",
                column: "FallbackFillerId");

            migrationBuilder.CreateIndex(
                name: "IX_ChannelTemplate_FFmpegProfileId",
                table: "ChannelTemplate",
                column: "FFmpegProfileId");

            migrationBuilder.CreateIndex(
                name: "IX_ChannelTemplate_MidRollFillerId",
                table: "ChannelTemplate",
                column: "MidRollFillerId");

            migrationBuilder.CreateIndex(
                name: "IX_ChannelTemplate_Name",
                table: "ChannelTemplate",
                column: "Name",
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_ChannelTemplate_PostRollFillerId",
                table: "ChannelTemplate",
                column: "PostRollFillerId");

            migrationBuilder.CreateIndex(
                name: "IX_ChannelTemplate_PreRollFillerId",
                table: "ChannelTemplate",
                column: "PreRollFillerId");

            migrationBuilder.CreateIndex(
                name: "IX_ChannelTemplate_WatermarkId",
                table: "ChannelTemplate",
                column: "WatermarkId");
        }

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