<?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('numbering_sequences', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->string('document_type', 50)->comment('문서유형');
            $table->string('scope_key', 100)->default('')->comment('범위 키 (카테고리/모델별 구분)');
            $table->string('period_key', 20)->comment('기간 키: 260207(daily), 202602(monthly), 2026(yearly)');
            $table->unsignedInteger('last_sequence')->default(0)->comment('마지막 시퀀스 번호');
            $table->timestamps();

            $table->unique(
                ['tenant_id', 'document_type', 'scope_key', 'period_key'],
                'uq_numbering_sequence'
            );
        });
    }

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