<?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::table('shop_products', function (Blueprint $table) {
            $table->unsignedBigInteger('shop_id')->nullable()->after('account_id');
            $table->unsignedBigInteger('local_id')->nullable()->after('id');
            $table->string('shop_product_sku')->nullable()->after('name');
            $table->string('shop_product_barcode')->nullable()->after('shop_product_sku');
            $table->boolean('is_active')->default(true)->after('shop_product_barcode');
            
            $table->index('shop_id');
            $table->index('local_id');
            $table->index('shop_product_sku');
            $table->index('shop_product_barcode');
            
            $table->foreign('shop_id')->references('id')->on('accounts')->onDelete('set null');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('shop_products', function (Blueprint $table) {
            $table->dropForeign(['shop_id']);
            $table->dropIndex(['shop_id', 'local_id', 'shop_product_sku', 'shop_product_barcode']);
            $table->dropColumn(['shop_id', 'local_id', 'shop_product_sku', 'shop_product_barcode', 'is_active']);
        });
    }
};
