<?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('product_variations', function (Blueprint $table) {
            $table->id();
            $table->foreignId('product_id')->constrained('products')->onDelete('cascade');
            $table->string('size');
            $table->string('color');
            $table->string('color_hex', 7)->nullable();
            $table->string('sku', 100)->unique();
            $table->decimal('price_adjustment', 10, 2)->default(0);
            $table->integer('stock')->default(0);
            $table->timestamps();
            
            $table->index('product_id');
            $table->index('sku');
            $table->unique(['product_id', 'size', 'color'], 'product_size_color_unique');
        });
    }

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