<?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 $t) {
            $t->id();
            $t->string('slug')->unique();           // psauto, autoplus, ...
            $t->string('name');                      // PSauto SRL
            $t->string('display_name')->nullable();  // shown in UI
            $t->string('city')->nullable();
            $t->string('phone')->nullable();
            $t->string('email')->nullable();
            $t->string('contact_name')->nullable();

            $t->enum('status', ['trial', 'active', 'expired', 'suspended', 'archived'])
                ->default('trial');

            $t->foreignId('plan_id')->nullable()->constrained()->nullOnDelete();
            $t->timestamp('trial_ends_at')->nullable();
            $t->timestamp('active_until')->nullable();

            // White-label settings (preluat din cfg-ul prototipului AutoCRM.html).
            $t->json('settings')->nullable();
            // Compatibilitate cu stancl/tenancy v3 — stochează metadate libere.
            $t->json('data')->nullable();

            $t->timestamps();
            $t->softDeletes();

            $t->index(['status']);
        });
    }

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