using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace PowderCoating.Infrastructure.Migrations
{
    /// <inheritdoc />
    public partial class AddAiItemPrediction : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AddColumn<int>(
                name: "AiPredictionId",
                table: "QuoteItems",
                type: "int",
                nullable: true);

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

            migrationBuilder.CreateTable(
                name: "AiItemPredictions",
                columns: table => new
                {
                    Id = table.Column<int>(type: "int", nullable: false)
                        .Annotation("SqlServer:Identity", "1, 1"),
                    PredictedSurfaceAreaSqFt = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    PredictedMinutes = table.Column<int>(type: "int", nullable: false),
                    PredictedComplexity = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    PredictedUnitPrice = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
                    Confidence = table.Column<string>(type: "nvarchar(max)", nullable: false),
                    Reasoning = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    AiTags = table.Column<string>(type: "nvarchar(max)", nullable: true),
                    ConversationRounds = table.Column<int>(type: "int", nullable: false),
                    UserOverrodeEstimate = table.Column<bool>(type: "bit", nullable: false),
                    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_AiItemPredictions", x => x.Id);
                });

            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));

            migrationBuilder.CreateIndex(
                name: "IX_QuoteItems_AiPredictionId",
                table: "QuoteItems",
                column: "AiPredictionId");

            migrationBuilder.CreateIndex(
                name: "IX_JobItems_AiPredictionId",
                table: "JobItems",
                column: "AiPredictionId");

            migrationBuilder.AddForeignKey(
                name: "FK_JobItems_AiItemPredictions_AiPredictionId",
                table: "JobItems",
                column: "AiPredictionId",
                principalTable: "AiItemPredictions",
                principalColumn: "Id");

            migrationBuilder.AddForeignKey(
                name: "FK_QuoteItems_AiItemPredictions_AiPredictionId",
                table: "QuoteItems",
                column: "AiPredictionId",
                principalTable: "AiItemPredictions",
                principalColumn: "Id");
        }

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

            migrationBuilder.DropForeignKey(
                name: "FK_QuoteItems_AiItemPredictions_AiPredictionId",
                table: "QuoteItems");

            migrationBuilder.DropTable(
                name: "AiItemPredictions");

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

            migrationBuilder.DropIndex(
                name: "IX_JobItems_AiPredictionId",
                table: "JobItems");

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

            migrationBuilder.DropColumn(
                name: "AiPredictionId",
                table: "JobItems");

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 1,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 3, 27, 34, 112, DateTimeKind.Utc).AddTicks(697));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 2,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 3, 27, 34, 112, DateTimeKind.Utc).AddTicks(704));

            migrationBuilder.UpdateData(
                table: "PricingTiers",
                keyColumn: "Id",
                keyValue: 3,
                column: "CreatedAt",
                value: new DateTime(2026, 3, 11, 3, 27, 34, 112, DateTimeKind.Utc).AddTicks(706));
        }
    }
}
