<?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::table('item_variations', function (Blueprint $table) {
            $table->string('size')->nullable()->after('sku_suffix');
            $table->string('color')->nullable()->after('size');
            $table->string('unit')->nullable()->after('color');
            $table->decimal('length', 10, 2)->nullable()->after('unit');
            $table->decimal('width', 10, 2)->nullable()->after('length');
            $table->decimal('height', 10, 2)->nullable()->after('width');
            $table->decimal('weight', 10, 2)->nullable()->after('height');
            $table->string('weight_unit')->default('kg')->after('weight');
            $table->decimal('cost_price', 15, 4)->nullable()->after('weight_unit');
            $table->decimal('selling_price', 15, 4)->nullable()->after('cost_price');
            $table->boolean('is_active')->default(true)->after('selling_price');
            $table->text('description')->nullable()->after('is_active');

            // Add indexes
            $table->index(['item_id', 'is_active']);
            $table->index(['size', 'color']);
        });
    }

    public function down(): void
    {
        Schema::table('item_variations', function (Blueprint $table) {
            $table->dropIndex(['item_id', 'is_active']);
            $table->dropIndex(['size', 'color']);

            $table->dropColumn([
                'size', 'color', 'unit', 'length', 'width', 'height',
                'weight', 'weight_unit', 'cost_price', 'selling_price',
                'is_active', 'description'
            ]);
        });
    }
};
