<?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('manufacturers', function (Blueprint $table) {
            // Industry presence and market analysis fields
            $table->integer('industry_presence_score')->default(0)->after('total_roller_coasters');
            $table->decimal('market_share_percentage', 5, 2)->default(0.00)->after('industry_presence_score');
            $table->integer('founded_year')->nullable()->after('market_share_percentage');
            $table->string('specialization')->nullable()->after('founded_year');
            $table->text('product_portfolio')->nullable()->after('specialization');
            $table->json('manufacturing_categories')->nullable()->after('product_portfolio');
            $table->integer('global_installations')->default(0)->after('manufacturing_categories');
            $table->string('primary_market')->nullable()->after('global_installations');
            $table->boolean('is_major_manufacturer')->default(false)->after('primary_market');
            
            // Add indexes for performance
            $table->index('industry_presence_score');
            $table->index('market_share_percentage');
            $table->index('founded_year');
            $table->index('specialization');
            $table->index('is_major_manufacturer');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('manufacturers', function (Blueprint $table) {
            // Drop indexes first
            $table->dropIndex(['industry_presence_score']);
            $table->dropIndex(['market_share_percentage']);
            $table->dropIndex(['founded_year']);
            $table->dropIndex(['specialization']);
            $table->dropIndex(['is_major_manufacturer']);
            
            // Drop columns
            $table->dropColumn([
                'industry_presence_score',
                'market_share_percentage',
                'founded_year',
                'specialization',
                'product_portfolio',
                'manufacturing_categories',
                'global_installations',
                'primary_market',
                'is_major_manufacturer'
            ]);
        });
    }
};
