<?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('cotizaciones', function (Blueprint $table) {
            $table->id();
            $table->foreignId('caso_id')->constrained()->onDelete('cascade');
            $table->foreignId('taller_id')->constrained('talleres')->onDelete('cascade');
            $table->foreignId('proveedor_id')->nullable()->constrained('proveedores')->onDelete('set null');
            $table->enum('tipo', ['dealer', 'multimarca_dealer', 'multimarca', 'taller_asegurado']);
            $table->enum('estado', ['pendiente', 'enviada', 'aceptada', 'rechazada', 'vencida'])->default('pendiente');
            $table->enum('notificacion_tipo', ['stock', 'importacion'])->nullable();
            $table->timestamp('fecha_envio')->nullable();
            $table->timestamp('fecha_respuesta')->nullable();
            $table->timestamp('fecha_limite')->nullable();
            $table->text('observaciones')->nullable();
            $table->boolean('aceptada')->nullable();
            $table->timestamps();

            $table->index('estado');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('cotizaciones');
    }
};
