<?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('dictionaries', function (Blueprint $table) {
            $table->id();
            $table->string('name', 50)->comment('字典名称');
            $table->string('code', 50)->unique()->comment('字典编码');
            $table->string('description', 255)->nullable();
            $table->tinyInteger('is_system')->default(0)->comment('系统内置不可删');
            $table->timestamps();
        });

        Schema::create('dictionary_items', function (Blueprint $table) {
            $table->id();
            $table->foreignId('dictionary_id')->constrained()->onDelete('cascade');
            $table->string('label', 100)->comment('显示文本');
            $table->string('value', 100)->comment('值');
            $table->integer('sort')->default(0);
            $table->tinyInteger('status')->default(1)->comment('1启用 0停用');
            $table->timestamps();

            $table->index('dictionary_id');
        });
    }

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