<?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('sellers', function (Blueprint $table) {
            // Champs business info
            if (!Schema::hasColumn('sellers', 'business_name')) {
                if (!Schema::hasColumn('sellers', 'business_name')) { $table->string('business_name')->nullable(); }
            }
            if (!Schema::hasColumn('sellers', 'business_type')) {
                if (!Schema::hasColumn('sellers', 'business_type')) { $table->string('business_type')->nullable(); }
            }
            if (!Schema::hasColumn('sellers', 'business_registration')) {
                if (!Schema::hasColumn('sellers', 'business_registration')) { $table->string('business_registration')->nullable(); }
            }
            if (!Schema::hasColumn('sellers', 'tax_id')) {
                if (!Schema::hasColumn('sellers', 'tax_id')) { $table->string('tax_id')->nullable(); }
            }
            
            // Champs documents KYC individuels
            if (!Schema::hasColumn('sellers', 'id_document')) {
                if (!Schema::hasColumn('sellers', 'id_document')) { $table->string('id_document')->nullable(); }
            }
            if (!Schema::hasColumn('sellers', 'address_proof')) {
                if (!Schema::hasColumn('sellers', 'address_proof')) { $table->string('address_proof')->nullable(); }
            }
            if (!Schema::hasColumn('sellers', 'business_document')) {
                if (!Schema::hasColumn('sellers', 'business_document')) { $table->string('business_document')->nullable(); }
            }
            if (!Schema::hasColumn('sellers', 'business_photo')) {
                if (!Schema::hasColumn('sellers', 'business_photo')) { $table->string('business_photo')->nullable(); }
            }
            
            // Champs supplémentaires
            if (!Schema::hasColumn('sellers', 'kyc_submitted_at')) {
                if (!Schema::hasColumn('sellers', 'kyc_submitted_at')) { $table->timestamp('kyc_submitted_at')->nullable(); }
            }
            if (!Schema::hasColumn('sellers', 'kyc_verified_at')) {
                if (!Schema::hasColumn('sellers', 'kyc_verified_at')) { $table->timestamp('kyc_verified_at')->nullable(); }
            }
            if (!Schema::hasColumn('sellers', 'category')) {
                if (!Schema::hasColumn('sellers', 'category')) { $table->string('category')->nullable(); }
            }
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('sellers', function (Blueprint $table) {
            $columns = [
                'business_name', 'business_type', 'business_registration', 'tax_id',
                'id_document', 'address_proof', 'business_document', 'business_photo',
                'kyc_submitted_at', 'kyc_verified_at', 'category'
            ];
            
            foreach ($columns as $column) {
                if (Schema::hasColumn('sellers', $column)) {
                    $table->dropColumn($column);
                }
            }
        });
    }
};


