<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('investment_settings', function (Blueprint $table) {
            $table->id();
            $table->decimal('min_amount', 12, 2)->default(200);
            $table->decimal('max_amount', 12, 2)->default(50000);
            $table->decimal('monthly_return', 5, 2)->default(3.5);
            $table->string('payment_method')->default('TRC20');
            $table->string('payment_address')->default('TUjJn5yk7XvkESScqMqPvThPvvzJASK1BYN');
            $table->timestamps();
        });

        Schema::create('investment_durations', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('months')->unique();
            $table->string('label');
            $table->unsignedInteger('sort_order')->default(0);
            $table->boolean('is_active')->default(true);
            $table->timestamps();
        });

        DB::table('investment_settings')->insert([
            'min_amount' => 200,
            'max_amount' => 50000,
            'monthly_return' => 3.5,
            'payment_method' => 'TRC20',
            'payment_address' => 'TUjJn5yk7XvkESScqMqPvThPvvzJASK1BYN',
            'created_at' => now(),
            'updated_at' => now(),
        ]);

        foreach ([4, 8, 12] as $index => $months) {
            DB::table('investment_durations')->insert([
                'months' => $months,
                'label' => "{$months} meses",
                'sort_order' => $index,
                'is_active' => true,
                'created_at' => now(),
                'updated_at' => now(),
            ]);
        }
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('investment_durations');
        Schema::dropIfExists('investment_settings');
    }
};
