using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Elecciones.Database.Migrations
{
    /// <inheritdoc />
    public partial class LegislativasNacionales2025 : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "Telegramas",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "ResumenesVotos",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "ResultadosVotos",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "ProyeccionesBancas",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "OcupantesBancas",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "LogosAgrupacionesCategorias",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "EstadosRecuentosGenerales",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "EstadosRecuentos",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "CandidatosOverrides",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "EleccionId",
                table: "Bancadas",
                type: "int",
                nullable: false,
                defaultValue: 0);

            migrationBuilder.AddColumn<int>(
                name: "OrdenDiputadosNacionales",
                table: "AgrupacionesPoliticas",
                type: "int",
                nullable: true);

            migrationBuilder.AddColumn<int>(
                name: "OrdenSenadoresNacionales",
                table: "AgrupacionesPoliticas",
                type: "int",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "BancasPrevias",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    EleccionId = table.Column<int>(type: "int", nullable: false),
                    Camara = table.Column<int>(type: "int", nullable: false),
                    AgrupacionPoliticaId = table.Column<string>(type: "nvarchar(450)", nullable: false, collation: "Modern_Spanish_CI_AS"),
                    Cantidad = table.Column<int>(type: "int", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_BancasPrevias", x => x.Id);
                    table.ForeignKey(
                        name: "FK_BancasPrevias_AgrupacionesPoliticas_AgrupacionPoliticaId",
                        column: x => x.AgrupacionPoliticaId,
                        principalTable: "AgrupacionesPoliticas",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateTable(
                name: "Elecciones",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false),
                    Nombre = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Nivel = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    DistritoId = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Fecha = table.Column<DateOnly>(type: "date", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_Elecciones", x => x.Id);
                });

            migrationBuilder.CreateIndex(
                name: "IX_BancasPrevias_AgrupacionPoliticaId",
                table: "BancasPrevias",
                column: "AgrupacionPoliticaId");

            migrationBuilder.AddForeignKey(
                name: "FK_EstadosRecuentosGenerales_AmbitosGeograficos_AmbitoGeograficoId",
                table: "EstadosRecuentosGenerales",
                column: "AmbitoGeograficoId",
                principalTable: "AmbitosGeograficos",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropTable(
                name: "BancasPrevias");

            migrationBuilder.DropTable(
                name: "Elecciones");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "Telegramas");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "ResumenesVotos");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "ResultadosVotos");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "ProyeccionesBancas");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "OcupantesBancas");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "LogosAgrupacionesCategorias");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "EstadosRecuentosGenerales");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "EstadosRecuentos");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "CandidatosOverrides");

            migrationBuilder.DropColumn(
                name: "EleccionId",
                table: "Bancadas");

            migrationBuilder.DropColumn(
                name: "OrdenDiputadosNacionales",
                table: "AgrupacionesPoliticas");

            migrationBuilder.DropColumn(
                name: "OrdenSenadoresNacionales",
                table: "AgrupacionesPoliticas");
        }
    }
}
