<?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_entries', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id');
            $table->string('entry_no', 20)->comment('전표번호 JE-YYYYMMDD-NNN');
            $table->date('entry_date')->comment('전표일자');
            $table->string('entry_type', 20)->default('general')->comment('전표유형');
            $table->string('description', 500)->nullable()->comment('적요');
            $table->bigInteger('total_debit')->default(0)->comment('차변합계');
            $table->bigInteger('total_credit')->default(0)->comment('대변합계');
            $table->string('status', 20)->default('draft')->comment('상태: draft, confirmed');
            $table->string('created_by_name', 100)->nullable()->comment('작성자명');
            $table->text('attachment_note')->nullable()->comment('첨부메모');
            $table->timestamps();
            $table->softDeletes();

            $table->unique(['tenant_id', 'entry_no']);
            $table->index(['tenant_id', 'entry_date']);
            $table->index(['tenant_id', 'status']);
        });
    }

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