<?php

declare(strict_types=1);

use App\Enums\ProfessionalVerificationStatus;
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('professional_profiles', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrained()->cascadeOnDelete();
            $table->string('professional_name');
            $table->string('profile_type', 24);
            $table->string('logo_or_photo')->nullable();
            $table->foreignId('city_id')->nullable()->constrained()->nullOnDelete();
            $table->text('bio')->nullable();
            $table->boolean('phone_visible')->default(false);
            $table->boolean('email_visible')->default(false);
            $table->string('verification_status', 24)->default(ProfessionalVerificationStatus::Pending->value);
            $table->decimal('rating_average', 3, 2)->default(0);
            $table->unsignedInteger('total_requests')->default(0);
            $table->unsignedInteger('total_proposals')->default(0);
            $table->unsignedInteger('total_closed_deals')->default(0);
            $table->timestamps();

            $table->unique('user_id');

            // profile_type doit rester synchronisé avec users.account_type (agence ou indépendant).
            // La contrainte check n'est pas portable sur toutes les BDD ; enforcement côté app / FormRequests.
        });
    }

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