using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace MilitaryTrainingManagement.Migrations
{
    /// <inheritdoc />
    public partial class AddConsumptionReportTable : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<string>(
                name: "PlainPassword",
                table: "UserAccounts",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.AddColumn<string>(
                name: "Unit",
                table: "Personnel",
                type: "nvarchar(max)",
                nullable: true);

            migrationBuilder.CreateTable(
                name: "ConsumptionReports",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    AllocationDistributionId = table.Column<int>(type: "int", nullable: false),
                    ReportedAmount = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false),
                    CumulativeAmount = table.Column<decimal>(type: "decimal(18,2)", precision: 18, scale: 2, nullable: false),
                    Remarks = table.Column<string>(type: "nvarchar(500)", maxLength: 500, nullable: true),
                    ReportedByUserId = table.Column<int>(type: "int", nullable: false),
                    ReportedAt = table.Column<DateTime>(type: "datetime2", nullable: false)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_ConsumptionReports", x => x.Id);
                    table.ForeignKey(
                        name: "FK_ConsumptionReports_AllocationDistributions_AllocationDistributionId",
                        column: x => x.AllocationDistributionId,
                        principalTable: "AllocationDistributions",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                    table.ForeignKey(
                        name: "FK_ConsumptionReports_UserAccounts_ReportedByUserId",
                        column: x => x.ReportedByUserId,
                        principalTable: "UserAccounts",
                        principalColumn: "Id");
                });

            migrationBuilder.CreateIndex(
                name: "IX_ConsumptionReports_AllocationDistributionId",
                table: "ConsumptionReports",
                column: "AllocationDistributionId");

            migrationBuilder.CreateIndex(
                name: "IX_ConsumptionReports_ReportedAt",
                table: "ConsumptionReports",
                column: "ReportedAt");

            migrationBuilder.CreateIndex(
                name: "IX_ConsumptionReports_ReportedByUserId",
                table: "ConsumptionReports",
                column: "ReportedByUserId");
        }

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

            migrationBuilder.DropColumn(
                name: "PlainPassword",
                table: "UserAccounts");

            migrationBuilder.DropColumn(
                name: "Unit",
                table: "Personnel");
        }
    }
}
