<?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('beneficiaries', function (Blueprint $table) {
            $table->uuid('id')->primary();
            $table->uuid('user_id')->constrained()->cascadeOnDelete();
            $table->string('name');
            $table->enum('type', ['phone', 'meter', 'smartcard', 'customer_id', 'exam'])->index();
            $table->string('number');
            $table->string('network')->nullable();
            $table->string('service_type')->nullable();
            $table->string('variation_code')->nullable();
            $table->boolean('is_favorite')->default(false);
            $table->integer('usage_count')->default(0);
            $table->json('metadata')->nullable();
            $table->timestamps();
            $table->softDeletes();

            $table->index(['user_id', 'type']);
            $table->index(['user_id', 'is_favorite']);
        });
    }

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