<?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('journal_sequences', function (Blueprint $table) {
            $table->id();
            $table->foreignId('hotel_id')->constrained()->onDelete('cascade');
            $table->string('prefix');
            $table->string('year_month')->nullable(); // For date-based sequences (e.g. 202603)
            $table->unsignedInteger('last_value')->default(0);
            $table->timestamps();

            $table->unique(['hotel_id', 'prefix', 'year_month']);
        });
    }

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