<?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('admin_api_environments', function (Blueprint $table) {
            $table->id()->comment('ID');
            $table->foreignId('user_id')->comment('사용자 ID');
            $table->string('name', 50)->comment('환경 이름');
            $table->string('base_url', 500)->comment('기본 URL');
            $table->string('api_key', 500)->nullable()->comment('API 키 (암호화)');
            $table->text('auth_token')->nullable()->comment('인증 토큰 (암호화)');
            $table->json('variables')->nullable()->comment('환경 변수');
            $table->boolean('is_default')->default(false)->comment('기본 환경 여부');
            $table->timestamps();

            $table->index('user_id');

            $table->foreign('user_id')
                ->references('id')
                ->on('users')
                ->onDelete('cascade');
        });
    }

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