<?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
    {
        // Add API features to plans table
        Schema::table('plans', function (Blueprint $table) {
            $table->boolean('api_enabled')->default(false)->after('is_active');
            $table->integer('api_rate_limit_hour')->default(60)->after('api_enabled');
            $table->integer('api_rate_limit_day')->default(1000)->after('api_rate_limit_hour');
            $table->integer('api_max_tokens')->default(1)->after('api_rate_limit_day');
            $table->json('api_endpoints_access')->nullable()->after('api_max_tokens');
            $table->json('api_features')->nullable()->after('api_endpoints_access');
        });

        // Add API features to reseller_plans table
        Schema::table('reseller_plans', function (Blueprint $table) {
            $table->boolean('api_enabled')->default(false)->after('is_active');
            $table->integer('api_rate_limit_hour')->default(300)->after('api_enabled');
            $table->integer('api_rate_limit_day')->default(10000)->after('api_rate_limit_hour');
            $table->integer('api_max_tokens')->default(5)->after('api_rate_limit_day');
            $table->json('api_endpoints_access')->nullable()->after('api_max_tokens');
            $table->json('api_features')->nullable()->after('api_endpoints_access');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::table('plans', function (Blueprint $table) {
            $table->dropColumn([
                'api_enabled',
                'api_rate_limit_hour',
                'api_rate_limit_day',
                'api_max_tokens',
                'api_endpoints_access',
                'api_features'
            ]);
        });

        Schema::table('reseller_plans', function (Blueprint $table) {
            $table->dropColumn([
                'api_enabled',
                'api_rate_limit_hour',
                'api_rate_limit_day',
                'api_max_tokens',
                'api_endpoints_access',
                'api_features'
            ]);
        });
    }
};
