<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('inspections', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('property_name');
            $table->string('property_address')->nullable();
            $table->string('status')->default('scheduled')->index();
            $table->decimal('ai_confidence', 5, 2)->default(0);
            $table->decimal('estimated_cost', 12, 2)->default(0);
            $table->timestamp('scheduled_at')->nullable()->index();
            $table->timestamp('completed_at')->nullable();
            $table->timestamps();
        });

        Schema::create('damage_findings', function (Blueprint $table) {
            $table->id();
            $table->foreignId('inspection_id')->constrained()->cascadeOnDelete();
            $table->string('category');
            $table->string('severity')->default('medium')->index();
            $table->string('status')->default('review')->index();
            $table->decimal('confidence', 5, 2)->default(0);
            $table->decimal('estimated_repair_cost', 12, 2)->default(0);
            $table->text('notes')->nullable();
            $table->timestamps();
        });

        Schema::create('inspection_reports', function (Blueprint $table) {
            $table->id();
            $table->foreignId('inspection_id')->unique()->constrained()->cascadeOnDelete();
            $table->string('report_number')->unique();
            $table->string('status')->default('draft')->index();
            $table->text('summary')->nullable();
            $table->timestamp('published_at')->nullable();
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('inspection_reports');
        Schema::dropIfExists('damage_findings');
        Schema::dropIfExists('inspections');
    }
};
