<?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('companies', function (Blueprint $table) {
            $table->id();

            // Firma sahibi hesap (Agency Panel'e giren kullanıcı). Bir kullanıcının tek firması olabilir.
            $table->foreignId('user_id')->unique()->constrained('users')->cascadeOnDelete();

            $table->string('name');
            $table->string('slug')->unique();

            $table->string('logo')->nullable();
            $table->string('cover_image')->nullable();
            $table->string('email')->nullable();
            $table->string('phone')->nullable();
            $table->string('whatsapp_phone')->nullable();
            $table->string('website_url')->nullable();
            $table->string('instagram_url')->nullable();
            $table->string('linkedin_url')->nullable();

            $table->text('description')->nullable();
            $table->string('address')->nullable();
            $table->string('city')->nullable();
            $table->string('district')->nullable();
            $table->string('country')->nullable();
            $table->string('license_number')->nullable();

            // Başvuru akışı: pending → admin onayı → approved (Agency Panel açılır) / rejected (sebep + tekrar başvuru).
            $table->string('application_status')->default('pending'); // pending | approved | rejected
            $table->text('rejection_reason')->nullable();
            $table->timestamp('applied_at')->nullable();

            $table->boolean('is_active')->default(false);   // admin onayına kadar pasif
            $table->boolean('is_verified')->default(false); // güven rozeti (admin verir)
            $table->timestamp('verified_at')->nullable();

            $table->timestamps();

            $table->index(['application_status', 'applied_at']);
            $table->index('is_active');
        });
    }


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