<?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('leave_balances', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('user_id')->comment('사용자 ID');
            $table->unsignedSmallInteger('year')->comment('연도');
            $table->decimal('total_days', 4, 1)->default(15)->comment('연간 부여일수');
            $table->decimal('used_days', 4, 1)->default(0)->comment('사용일수');
            $table->decimal('remaining_days', 4, 1)->storedAs('total_days - used_days')->comment('잔여일수');
            $table->timestamps();

            $table->unique(['tenant_id', 'user_id', 'year'], 'uk_tenant_user_year');
        });
    }

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