<?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_regions', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('parent_id')->default(0)->comment('父级ID');
            $table->unsignedSmallInteger('level')->comment('层级:1省2市3区4乡镇');
            $table->string('code', 20)->comment('区划编码(6位或9位)');
            $table->string('name', 50)->comment('名称');
            $table->string('pinyin', 100)->nullable()->comment('拼音');
            $table->string('pinyin_prefix', 10)->nullable()->comment('拼音首字母');
            $table->unsignedSmallInteger('sort')->default(0);
            $table->timestamps();

            $table->unique(['code', 'level']);
            $table->index('parent_id');
            $table->index('level');
        });
    }

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