<?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::create('system_field_definitions', function (Blueprint $table) {
            $table->id();
            $table->string('source_table', 100)->comment('소스 테이블명');
            $table->string('source_table_label', 100)->comment('소스 테이블 라벨');
            $table->string('field_key', 100)->comment('필드 키');
            $table->string('field_name', 100)->comment('필드명');
            $table->string('field_type', 50)->comment('필드 타입');
            $table->integer('order_no')->default(0)->comment('정렬 순서');
            $table->boolean('is_required')->default(false)->comment('필수 여부');
            $table->boolean('is_seed_default')->default(true)->comment('기본 시딩 대상');
            $table->string('default_value')->nullable()->comment('기본값');
            $table->json('options')->nullable()->comment('옵션');
            $table->boolean('is_active')->default(true)->comment('활성 여부');
            $table->timestamps();

            $table->index(['source_table', 'is_active']);
            $table->unique(['source_table', 'field_key']);
        });
    }

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