using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PowderCoating.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddMerchandise : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropIndex(
                name: "IX_Invoices_CompanyId_JobId",
                table: "Invoices");

            migrationBuilder.DropIndex(
                name: "IX_Invoices_JobId",
                table: "Invoices");

            migrationBuilder.AlterColumn<int>(
                name: "JobId",
                table: "Invoices",
                type: "int",
                nullable: true,
                oldClrType: typeof(int),
                oldType: "int");

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

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

            migrationBuilder.AddColumn<bool>(
                name: "IsMerchandise",
                table: "CatalogItems",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.AddColumn<bool>(
                name: "IsMerchandise",
                table: "CatalogCategories",
                type: "bit",
                nullable: false,
                defaultValue: false);

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 1,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 29, 13, 47, 49, 417, DateTimeKind.Utc).AddTicks(6542));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 2,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 29, 13, 47, 49, 417, DateTimeKind.Utc).AddTicks(6549));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 3,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 29, 13, 47, 49, 417, DateTimeKind.Utc).AddTicks(6551));

            migrationBuilder.CreateIndex(
                name: "IX_Invoices_CompanyId_JobId",
                table: "Invoices",
                columns: new[] { "CompanyId", "JobId" },
                unique: true,
                filter: "[JobId] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_Invoices_JobId",
                table: "Invoices",
                column: "JobId",
                unique: true,
                filter: "[JobId] IS NOT NULL");

            migrationBuilder.CreateIndex(
                name: "IX_InvoiceItems_CatalogItemId",
                table: "InvoiceItems",
                column: "CatalogItemId");

            migrationBuilder.CreateIndex(
                name: "IX_CatalogItems_InventoryItemId",
                table: "CatalogItems",
                column: "InventoryItemId");

            migrationBuilder.AddForeignKey(
                name: "FK_CatalogItems_InventoryItems_InventoryItemId",
                table: "CatalogItems",
                column: "InventoryItemId",
                principalTable: "InventoryItems",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_InvoiceItems_CatalogItems_CatalogItemId",
                table: "InvoiceItems",
                column: "CatalogItemId",
                principalTable: "CatalogItems",
                principalColumn: "Id");
        }

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

            migrationBuilder.DropForeignKey(
                name: "FK_InvoiceItems_CatalogItems_CatalogItemId",
                table: "InvoiceItems");

            migrationBuilder.DropIndex(
                name: "IX_Invoices_CompanyId_JobId",
                table: "Invoices");

            migrationBuilder.DropIndex(
                name: "IX_Invoices_JobId",
                table: "Invoices");

            migrationBuilder.DropIndex(
                name: "IX_InvoiceItems_CatalogItemId",
                table: "InvoiceItems");

            migrationBuilder.DropIndex(
                name: "IX_CatalogItems_InventoryItemId",
                table: "CatalogItems");

            migrationBuilder.DropColumn(
                name: "CatalogItemId",
                table: "InvoiceItems");

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

            migrationBuilder.DropColumn(
                name: "IsMerchandise",
                table: "CatalogItems");

            migrationBuilder.DropColumn(
                name: "IsMerchandise",
                table: "CatalogCategories");

            migrationBuilder.AlterColumn<int>(
                name: "JobId",
                table: "Invoices",
                type: "int",
                nullable: false,
                defaultValue: 0,
                oldClrType: typeof(int),
                oldType: "int",
                oldNullable: true);

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 1,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 29, 0, 58, 35, 757, DateTimeKind.Utc).AddTicks(6949));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 2,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 29, 0, 58, 35, 757, DateTimeKind.Utc).AddTicks(6955));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 3,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 29, 0, 58, 35, 757, DateTimeKind.Utc).AddTicks(6957));

            migrationBuilder.CreateIndex(
                name: "IX_Invoices_CompanyId_JobId",
                table: "Invoices",
                columns: new[] { "CompanyId", "JobId" },
                unique: true);

            migrationBuilder.CreateIndex(
                name: "IX_Invoices_JobId",
                table: "Invoices",
                column: "JobId",
                unique: true);
        }
    }
}
