<?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('propostas', function (Blueprint $table) {
            $table->id();
            $table->string('token', 64)->unique();
            $table->string('razao_social');
            $table->string('cnpj')->nullable();
            $table->string('email');
            $table->string('telefone')->nullable();
            $table->string('regime_tributario');
            $table->decimal('honorario_calculado', 10, 2)->default(0);
            $table->decimal('honorario_final', 10, 2)->default(0);
            $table->json('detalhes')->nullable();
            $table->text('observacoes')->nullable();
            $table->date('validade');
            $table->enum('status', ['rascunho', 'enviada', 'aceita', 'recusada', 'expirada'])->default('rascunho');
            $table->timestamp('aceita_em')->nullable();
            $table->string('aceita_por_ip')->nullable();
            $table->foreignId('user_id')->nullable()->constrained()->nullOnDelete();
            $table->timestamps();
        });
    }

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