<?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('license_activations', function (Blueprint $table): void {
            $table->id();
            $table->string('license_key', 191);
            $table->string('user_id', 64);
            $table->string('product', 32)->default('site');
            $table->string('device_id', 191)->nullable();
            $table->string('status', 32)->default('active');
            $table->timestamps();

            $table->unique(['license_key', 'product', 'device_id'], 'uniq_license_product_device');
            $table->index(['license_key', 'product', 'status'], 'idx_license_product_status');
            $table->index(['user_id', 'status'], 'idx_user_status');
        });
    }

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