using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PowderCoating.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddPowderUsageLog : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.CreateTable(
                name: "PowderUsageLogs",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    JobId = table.Column<int>(type: "int", nullable: false),
                    JobItemId = table.Column<int>(type: "int", nullable: false),
                    JobItemCoatId = table.Column<int>(type: "int", nullable: false),
                    InventoryItemId = table.Column<int>(type: "int", nullable: true),
                    InventoryTransactionId = table.Column<int>(type: "int", nullable: true),
                    ActualLbsUsed = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    EstimatedLbs = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    VarianceLbs = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    RecordedByUserId = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    RecordedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    Notes = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CompanyId = table.Column<int>(type: "int", nullable: false),
                    CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: false),
                    UpdatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    CreatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    UpdatedBy = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    IsDeleted = table.Column<bool>(type: "bit", nullable: false),
                    DeletedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
                    DeletedBy = table.Column<string>(type: "nvarchar(max)", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_PowderUsageLogs", x => x.Id);
                    table.ForeignKey(
                        name: "FK_PowderUsageLogs_InventoryItems_InventoryItemId",
                        column: x => x.InventoryItemId,
                        principalTable: "InventoryItems",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_PowderUsageLogs_InventoryTransactions_InventoryTransactionId",
                        column: x => x.InventoryTransactionId,
                        principalTable: "InventoryTransactions",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_PowderUsageLogs_JobItemCoats_JobItemCoatId",
                        column: x => x.JobItemCoatId,
                        principalTable: "JobItemCoats",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_PowderUsageLogs_JobItems_JobItemId",
                        column: x => x.JobItemId,
                        principalTable: "JobItems",
                        principalColumn: "Id");
                    table.ForeignKey(
                        name: "FK_PowderUsageLogs_Jobs_JobId",
                        column: x => x.JobId,
                        principalTable: "Jobs",
                        principalColumn: "Id");
                });

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 1,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 13, 10, 22, 98, DateTimeKind.Utc).AddTicks(2050));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 2,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 13, 10, 22, 98, DateTimeKind.Utc).AddTicks(2056));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 3,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 13, 10, 22, 98, DateTimeKind.Utc).AddTicks(2058));

            migrationBuilder.CreateIndex(
                name: "IX_PowderUsageLogs_InventoryItemId",
                table: "PowderUsageLogs",
                column: "InventoryItemId");

            migrationBuilder.CreateIndex(
                name: "IX_PowderUsageLogs_InventoryTransactionId",
                table: "PowderUsageLogs",
                column: "InventoryTransactionId");

            migrationBuilder.CreateIndex(
                name: "IX_PowderUsageLogs_JobId",
                table: "PowderUsageLogs",
                column: "JobId");

            migrationBuilder.CreateIndex(
                name: "IX_PowderUsageLogs_JobItemCoatId",
                table: "PowderUsageLogs",
                column: "JobItemCoatId");

            migrationBuilder.CreateIndex(
                name: "IX_PowderUsageLogs_JobItemId",
                table: "PowderUsageLogs",
                column: "JobItemId");
        }

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

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 1,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 12, 50, 33, 934, DateTimeKind.Utc).AddTicks(4668));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 2,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 12, 50, 33, 934, DateTimeKind.Utc).AddTicks(4675));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 3,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 12, 50, 33, 934, DateTimeKind.Utc).AddTicks(4677));
        }
    }
}
