<?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('products', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug')->unique();
            $table->text('description')->nullable();
            $table->text('short_description')->nullable();
            $table->enum('type', ['software', 'plugin', 'module', 'theme', 'api', 'website', 'script', 'desktop', 'saas'])->default('software');
            $table->string('version')->default('1.0.0');
            $table->string('image')->nullable();
            $table->decimal('price', 10, 2)->default(0);
            $table->boolean('is_active')->default(true);
            $table->boolean('is_featured')->default(false);
            $table->json('platforms')->nullable(); // ['php', 'wordpress', 'laravel']
            $table->json('license_rules')->nullable();
            $table->string('update_channel')->default('stable'); // stable, beta, rc
            $table->string('repo_path')->nullable();
            $table->unsignedInteger('max_activations')->nullable(); // null = unlimited
            $table->boolean('allow_domain_activation')->default(true);
            $table->boolean('allow_ip_activation')->default(false);
            $table->boolean('require_device_fingerprint')->default(false);
            $table->timestamps();
            $table->softDeletes();

            $table->index(['type', 'is_active']);
            $table->index('slug');
        });
    }

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