<?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('kylin_dict_types', function (Blueprint $table) {
            $table->id();
            $table->string('code', 50)->unique()->comment('类型编码');
            $table->string('name', 100)->comment('类型名称');
            $table->string('description', 255)->nullable();
            $table->timestamps();
            $table->softDeletes();
        });

        Schema::create('kylin_dict_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('type_id')->constrained('kylin_dict_types')->cascadeOnDelete();
            $table->string('label', 100)->comment('显示文本');
            $table->string('value', 100)->comment('存储值');
            $table->unsignedInteger('sort')->default(0)->comment('排序');
            $table->string('description', 255)->nullable();
            $table->unsignedTinyInteger('status')->default(1)->comment('0禁用1启用');
            $table->timestamps();
            $table->softDeletes();
            $table->unique(['type_id', 'value']);
        });
    }

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