using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Elecciones.Database.Migrations
{
    /// <inheritdoc />
    public partial class MakeEstadoGeneralKeyComposite : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropPrimaryKey(
                name: "PK_EstadosRecuentosGenerales",
                table: "EstadosRecuentosGenerales");

            migrationBuilder.AlterColumn<decimal>(
                name: "PorcentajeVotos",
                table: "ResultadosVotos",
                type: "decimal(18,4)",
                precision: 18,
                scale: 4,
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "decimal(18,2)");

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

            migrationBuilder.AlterColumn<decimal>(
                name: "VotosRecurridosPorcentaje",
                table: "EstadosRecuentos",
                type: "decimal(18,4)",
                precision: 18,
                scale: 4,
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "decimal(18,2)");

            migrationBuilder.AlterColumn<decimal>(
                name: "VotosNulosPorcentaje",
                table: "EstadosRecuentos",
                type: "decimal(18,4)",
                precision: 18,
                scale: 4,
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "decimal(18,2)");

            migrationBuilder.AlterColumn<decimal>(
                name: "VotosEnBlancoPorcentaje",
                table: "EstadosRecuentos",
                type: "decimal(18,4)",
                precision: 18,
                scale: 4,
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "decimal(18,2)");

            migrationBuilder.AddPrimaryKey(
                name: "PK_EstadosRecuentosGenerales",
                table: "EstadosRecuentosGenerales",
                columns: new[] { "AmbitoGeograficoId", "CategoriaId" });

            migrationBuilder.CreateIndex(
                name: "IX_EstadosRecuentosGenerales_CategoriaId",
                table: "EstadosRecuentosGenerales",
                column: "CategoriaId");

            migrationBuilder.AddForeignKey(
                name: "FK_EstadosRecuentosGenerales_CategoriasElectorales_CategoriaId",
                table: "EstadosRecuentosGenerales",
                column: "CategoriaId",
                principalTable: "CategoriasElectorales",
                principalColumn: "Id",
                onDelete: ReferentialAction.Cascade);
        }

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

            migrationBuilder.DropPrimaryKey(
                name: "PK_EstadosRecuentosGenerales",
                table: "EstadosRecuentosGenerales");

            migrationBuilder.DropIndex(
                name: "IX_EstadosRecuentosGenerales_CategoriaId",
                table: "EstadosRecuentosGenerales");

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

            migrationBuilder.AlterColumn<decimal>(
                name: "PorcentajeVotos",
                table: "ResultadosVotos",
                type: "decimal(18,2)",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "decimal(18,4)",
                oldPrecision: 18,
                oldScale: 4);

            migrationBuilder.AlterColumn<decimal>(
                name: "VotosRecurridosPorcentaje",
                table: "EstadosRecuentos",
                type: "decimal(18,2)",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "decimal(18,4)",
                oldPrecision: 18,
                oldScale: 4);

            migrationBuilder.AlterColumn<decimal>(
                name: "VotosNulosPorcentaje",
                table: "EstadosRecuentos",
                type: "decimal(18,2)",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "decimal(18,4)",
                oldPrecision: 18,
                oldScale: 4);

            migrationBuilder.AlterColumn<decimal>(
                name: "VotosEnBlancoPorcentaje",
                table: "EstadosRecuentos",
                type: "decimal(18,2)",
                nullable: false,
                oldClrType: typeof(decimal),
                oldType: "decimal(18,4)",
                oldPrecision: 18,
                oldScale: 4);

            migrationBuilder.AddPrimaryKey(
                name: "PK_EstadosRecuentosGenerales",
                table: "EstadosRecuentosGenerales",
                column: "AmbitoGeograficoId");
        }
    }
}
