<?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::create('investment_opportunities', function (Blueprint $table) {
            $table->id();
            $table->string('code', 10)->unique();
            $table->string('title_pt');
            $table->string('title_en')->nullable();
            $table->text('description_pt');
            $table->text('description_en')->nullable();
            $table->enum('sector', [
                'infraestrutura', 'agricultura', 'turismo', 'energia',
                'pescas', 'tecnologia', 'comercio', 'industria',
                'mineracao', 'saude', 'educacao'
            ]);
            $table->enum('status', ['draft', 'pronto', 'em_analise', 'fechado'])->default('draft');
            $table->boolean('is_featured')->default(false);
            $table->boolean('is_special_economic_zone')->default(false);
            $table->json('tags')->nullable();
            $table->foreignId('province_id')->nullable()->constrained('provinces');
            $table->foreignId('district_id')->nullable()->constrained('districts');
            $table->text('address')->nullable();
            $table->decimal('latitude', 10, 8)->nullable();
            $table->decimal('longitude', 11, 8)->nullable();
            $table->decimal('min_investment', 20, 2);
            $table->decimal('max_investment', 20, 2)->nullable();
            $table->decimal('expected_return_rate', 5, 2)->nullable();
            $table->integer('return_period_years')->nullable();
            $table->integer('total_jobs')->default(0);
            $table->json('images')->nullable();
            $table->json('documents')->nullable();
            $table->foreignId('created_by')->constrained('users');
            $table->foreignId('updated_by')->nullable()->constrained('users');
            $table->timestamp('published_at')->nullable();
            $table->timestamp('closed_at')->nullable();
            $table->timestamps();
            $table->softDeletes();
            $table->index(['status', 'sector']);
            $table->index(['is_featured', 'status']);
            $table->index(['province_id', 'status']);
            $table->index('code');
            $table->index('published_at');
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('investment_opportunities');
    }
};
