<?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('partners', function (Blueprint $table) {
            $table->id();
            $table->foreignId('company_id')->constrained()->cascadeOnDelete();

            // Identity
            $table->string('name');
            $table->string('document_type')->nullable(); // cc, nit, passport
            $table->string('document_number')->nullable();
            $table->string('email')->nullable();
            $table->string('phone')->nullable();

            // Ownership model
            $table->enum('ownership_model', ['fixed', 'dynamic'])->default('dynamic');
            $table->decimal('fixed_ownership_percentage', 8, 4)->nullable();

            // Status
            $table->enum('status', ['active', 'inactive', 'suspended'])->default('active');
            $table->date('joined_at');
            $table->date('exited_at')->nullable();

            // Notes
            $table->text('notes')->nullable();
            $table->json('metadata')->nullable();

            $table->timestamps();

            // Indexes
            $table->index(['company_id', 'status']);
            $table->unique(['company_id', 'document_number']);
        });
    }

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