using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Elecciones.Database.Migrations
{
    /// <inheritdoc />
    public partial class AddCandidatosOverridesTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "CandidatosOverrides",
                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),
                    AmbitoGeograficoId = table.Column<int>(type: "int", nullable: true),
                    NombreCandidato = table.Column<string>(type: "nvarchar(255)", maxLength: 255, nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_CandidatosOverrides", x => x.Id);
                    table.ForeignKey(
                        name: "FK_CandidatosOverrides_AgrupacionesPoliticas_AgrupacionPoliticaId",
                        column: x => x.AgrupacionPoliticaId,
                        principalTable: "AgrupacionesPoliticas",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_CandidatosOverrides_AmbitosGeograficos_AmbitoGeograficoId",
                        column: x => x.AmbitoGeograficoId,
                        principalTable: "AmbitosGeograficos",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_CandidatosOverrides_CategoriasElectorales_CategoriaId",
                        column: x => x.CategoriaId,
                        principalTable: "CategoriasElectorales",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_CandidatosOverrides_AgrupacionPoliticaId_CategoriaId_AmbitoGeograficoId",
                table: "CandidatosOverrides",
                columns: new[] { "AgrupacionPoliticaId", "CategoriaId", "AmbitoGeograficoId" },
                unique: true,
                filter: "[AmbitoGeograficoId] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_CandidatosOverrides_AmbitoGeograficoId",
                table: "CandidatosOverrides",
                column: "AmbitoGeograficoId");

            migrationBuilder.CreateIndex(
                name: "IX_CandidatosOverrides_CategoriaId",
                table: "CandidatosOverrides",
                column: "CategoriaId");
        }

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