<?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();
            $table->string('name', 100);                        // "Fedef", "Gessig", "Fycls", "Trexdi"
            $table->string('slug', 50)->unique();               // "fedef", "gessig"
            $table->string('legal_name', 200)->nullable();      // razón social
            $table->string('nit', 30)->nullable();              // identificación fiscal
            $table->string('domain', 100)->nullable();          // ej: fedef-co.com → auto-asignación por dominio de email
            $table->string('logo_path', 255)->nullable();       // /storage/companies/fedef/logo.png
            $table->string('primary_color', 7)->default('#1d4ed8'); // hex color para branding
            $table->string('contact_email', 150)->nullable();
            $table->string('contact_phone', 50)->nullable();
            $table->boolean('is_active')->default(true);
            $table->boolean('is_operator')->default(false);     // TRUE para Fycls (operadora)
            $table->json('settings')->nullable();               // configuraciones libres
            $table->integer('order')->default(0);
            $table->timestamps();
            $table->softDeletes();

            $table->index('is_active');
            $table->index('is_operator');
        });
    }

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