using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PowderCoating.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddQuoteItemCoatsSupport : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_QuoteItems_InventoryItems_InventoryItemId",
                table: "QuoteItems");

            migrationBuilder.DropIndex(
                name: "IX_QuoteItems_InventoryItemId",
                table: "QuoteItems");

            migrationBuilder.DropColumn(
                name: "ColorCode",
                table: "QuoteItems");

            migrationBuilder.DropColumn(
                name: "ColorName",
                table: "QuoteItems");

            migrationBuilder.DropColumn(
                name: "Finish",
                table: "QuoteItems");

            migrationBuilder.DropColumn(
                name: "InventoryItemId",
                table: "QuoteItems");

            migrationBuilder.DropColumn(
                name: "PowderCostOverride",
                table: "QuoteItems");

            migrationBuilder.CreateTable(
                name: "QuoteItemCoats",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    QuoteItemId = table.Column<int>(type: "int", nullable: false),
                    CoatName = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Sequence = table.Column<int>(type: "int", nullable: false),
                    InventoryItemId = table.Column<int>(type: "int", nullable: true),
                    ColorName = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ColorCode = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    Finish = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    CoverageSqFtPerLb = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    TransferEfficiency = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    PowderCostPerLb = table.Column<decimal>(type: "decimal(18,2)", nullable: true),
                    CoatMaterialCost = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    CoatLaborCost = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    CoatTotalCost = table.Column<decimal>(type: "decimal(18,2)", 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_QuoteItemCoats", x => x.Id);
                    table.ForeignKey(
                        name: "FK_QuoteItemCoats_Companies_CompanyId",
                        column: x => x.CompanyId,
                        principalTable: "Companies",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_QuoteItemCoats_InventoryItems_InventoryItemId",
                        column: x => x.InventoryItemId,
                        principalTable: "InventoryItems",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Restrict);
                    table.ForeignKey(
                        name: "FK_QuoteItemCoats_QuoteItems_QuoteItemId",
                        column: x => x.QuoteItemId,
                        principalTable: "QuoteItems",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 1,
                column: "CreatedAt",
                value: new DateTime(2026, 2, 15, 15, 49, 0, 479, DateTimeKind.Utc).AddTicks(9039));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 2,
                column: "CreatedAt",
                value: new DateTime(2026, 2, 15, 15, 49, 0, 479, DateTimeKind.Utc).AddTicks(9044));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 3,
                column: "CreatedAt",
                value: new DateTime(2026, 2, 15, 15, 49, 0, 479, DateTimeKind.Utc).AddTicks(9046));

            migrationBuilder.CreateIndex(
                name: "IX_QuoteItemCoats_CompanyId",
                table: "QuoteItemCoats",
                column: "CompanyId");

            migrationBuilder.CreateIndex(
                name: "IX_QuoteItemCoats_InventoryItemId",
                table: "QuoteItemCoats",
                column: "InventoryItemId");

            migrationBuilder.CreateIndex(
                name: "IX_QuoteItemCoats_QuoteItemId",
                table: "QuoteItemCoats",
                column: "QuoteItemId");
        }

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

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

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

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

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

            migrationBuilder.AddColumn<decimal>(
                name: "PowderCostOverride",
                table: "QuoteItems",
                type: "decimal(18,2)",
                nullable: true);

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 1,
                column: "CreatedAt",
                value: new DateTime(2026, 2, 15, 5, 5, 35, 315, DateTimeKind.Utc).AddTicks(9644));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 2,
                column: "CreatedAt",
                value: new DateTime(2026, 2, 15, 5, 5, 35, 315, DateTimeKind.Utc).AddTicks(9650));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 3,
                column: "CreatedAt",
                value: new DateTime(2026, 2, 15, 5, 5, 35, 315, DateTimeKind.Utc).AddTicks(9652));

            migrationBuilder.CreateIndex(
                name: "IX_QuoteItems_InventoryItemId",
                table: "QuoteItems",
                column: "InventoryItemId");

            migrationBuilder.AddForeignKey(
                name: "FK_QuoteItems_InventoryItems_InventoryItemId",
                table: "QuoteItems",
                column: "InventoryItemId",
                principalTable: "InventoryItems",
                principalColumn: "Id");
        }
    }
}
