using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Elecciones.Database.Migrations
{
    /// <inheritdoc />
    public partial class AddLogoAgrupacionCategoriaTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<string>(
                name: "AgrupacionPoliticaId",
                table: "ResumenesVotos",
                type: "nvarchar(450)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)");

            migrationBuilder.CreateTable(
                name: "LogosAgrupacionesCategorias",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    AgrupacionPoliticaId = table.Column<string>(type: "nvarchar(450)", nullable: false),
                    CategoriaId = table.Column<int>(type: "int", nullable: false),
                    LogoUrl = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_LogosAgrupacionesCategorias", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_ResumenesVotos_AgrupacionPoliticaId",
                table: "ResumenesVotos",
                column: "AgrupacionPoliticaId");

            migrationBuilder.CreateIndex(
                name: "IX_LogosAgrupacionesCategorias_AgrupacionPoliticaId_CategoriaId",
                table: "LogosAgrupacionesCategorias",
                columns: new[] { "AgrupacionPoliticaId", "CategoriaId" },
                unique: true);

            migrationBuilder.AddForeignKey(
                name: "FK_ResumenesVotos_AgrupacionesPoliticas_AgrupacionPoliticaId",
                table: "ResumenesVotos",
                column: "AgrupacionPoliticaId",
                principalTable: "AgrupacionesPoliticas",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropTable(
                name: "LogosAgrupacionesCategorias");

            migrationBuilder.DropIndex(
                name: "IX_ResumenesVotos_AgrupacionPoliticaId",
                table: "ResumenesVotos");

            migrationBuilder.AlterColumn<string>(
                name: "AgrupacionPoliticaId",
                table: "ResumenesVotos",
                type: "nvarchar(max)",
                nullable: false,
                oldClrType: typeof(string),
                oldType: "nvarchar(450)");
        }
    }
}
