<?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('sellers', function (Blueprint $table) {
            if (!Schema::hasColumn('sellers', 'moq_quantity')) {
                $table->integer('moq_quantity')->default(0)->nullable();
            }
            if (!Schema::hasColumn('sellers', 'moq_range_start')) {
                $table->integer('moq_range_start')->default(10);
            }
            if (!Schema::hasColumn('sellers', 'moq_range_end')) {
                $table->integer('moq_range_end')->default(150);
            }
            
            // Re-attempt category_id
            if (!Schema::hasColumn('sellers', 'category_id')) {
                // Remove foreign key constraint for safety if it fails, or try simplified
                $table->unsignedBigInteger('category_id')->nullable();
                // $table->foreign('category_id')->references('id')->on('categories')->nullOnDelete(); 
                // Separate FK adding if needed, but for now just column
            }

            if (!Schema::hasColumn('sellers', 'pan_number')) {
                $table->string('pan_number')->nullable();
            }
             if (!Schema::hasColumn('sellers', 'pan_doc')) {
                $table->string('pan_doc')->nullable();
            }
            if (!Schema::hasColumn('sellers', 'kyc_status')) {
                $table->string('kyc_status')->default('pending');
            }
        });
    }

    public function down(): void
    {
        Schema::table('sellers', function (Blueprint $table) {
            // Drop handled gracefully by DB usually, or ignore
        });
    }
};
