<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('product_variants', function (Blueprint $table) {
            $table->id();
            $table->foreignId('game_id')->constrained()->cascadeOnDelete();
            $table->string('sku')->unique();
            $table->string('name_ar');
            $table->string('name_en');
            $table->string('delivery_method')->default('manual')->index();
            $table->unsignedInteger('quantity')->default(1);
            $table->string('unit_ar')->default('وحدة');
            $table->string('unit_en')->default('Unit');
            $table->unsignedBigInteger('cost_minor')->default(0);
            $table->unsignedBigInteger('price_minor');
            $table->unsignedBigInteger('sale_price_minor')->nullable();
            $table->char('currency_code', 3)->default('EGP');
            $table->unsignedInteger('cashback_basis_points')->default(0);
            $table->unsignedInteger('loyalty_points')->default(0);
            $table->unsignedInteger('stock_available')->default(0);
            $table->unsignedInteger('min_stock_alert')->default(5);
            $table->string('status')->default('active')->index();
            $table->boolean('is_featured')->default(false)->index();
            $table->boolean('is_best_seller')->default(false)->index();
            $table->json('dynamic_fields')->nullable();
            $table->text('instructions_ar')->nullable();
            $table->text('instructions_en')->nullable();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('product_variants');
    }
};
