<?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('licenses', function (Blueprint $table): void {
            $table->string('license_key', 191)->primary();
            $table->string('source', 32)->nullable();
            $table->string('plan', 32)->default('pro');
            $table->string('status', 32)->default('active');
            $table->string('product_id', 191)->nullable();
            $table->string('owner_user_id', 64)->nullable()->index();
            $table->timestamp('expires_at')->nullable();
            $table->timestamp('last_verified_at')->nullable();
            $table->json('meta_json')->nullable();
            $table->timestamps();

            $table->index(['status', 'expires_at']);
        });
    }

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