using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace SolutionErp.Infrastructure.Persistence.Migrations
{
    /// <inheritdoc />
    public partial class AddProBudgetSplitToPeWorkItemBudget : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<decimal>(
                name: "ProAdjustmentAmount",
                table: "PeWorkItemBudgets",
                type: "decimal(18,2)",
                precision: 18,
                scale: 2,
                nullable: true);

            migrationBuilder.AddColumn<decimal>(
                name: "ProInitialAmount",
                table: "PeWorkItemBudgets",
                type: "decimal(18,2)",
                precision: 18,
                scale: 2,
                nullable: true);

            // [S76] Giu so PRO cu: so du tru 1-cot (ProEstimateAmount, <=S75) coi nhu
            // "ban hanh lan dau" cot PRO -> migrate sang ProInitialAmount. Chay SAU
            // AddColumn (cot phai ton tai truoc). Idempotent: chi set khi ProInitial trong.
            // Design-DB 0 rows; chay THAT lan dau tren prod co data (gotcha #64).
            migrationBuilder.Sql(@"
UPDATE PeWorkItemBudgets
SET ProInitialAmount = ProEstimateAmount
WHERE ProEstimateAmount IS NOT NULL AND ProInitialAmount IS NULL;");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropColumn(
                name: "ProAdjustmentAmount",
                table: "PeWorkItemBudgets");

            migrationBuilder.DropColumn(
                name: "ProInitialAmount",
                table: "PeWorkItemBudgets");
        }
    }
}
