<?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_grants', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id')->comment('테넌트 ID');
            $table->unsignedBigInteger('user_id')->comment('부여 대상자 ID');
            $table->string('grant_type', 20)->comment('부여유형: annual/monthly/reward/condolence/other');
            $table->date('grant_date')->comment('부여일');
            $table->decimal('grant_days', 4, 1)->comment('부여일수');
            $table->text('reason')->nullable()->comment('부여 사유');
            $table->unsignedBigInteger('created_by')->nullable()->comment('부여자 ID');
            $table->unsignedBigInteger('updated_by')->nullable()->comment('수정자');
            $table->unsignedBigInteger('deleted_by')->nullable()->comment('삭제자');
            $table->softDeletes();
            $table->timestamps();

            $table->index(['tenant_id', 'user_id'], 'idx_tenant_user');
            $table->index('grant_date', 'idx_grant_date');
            $table->index('grant_type', 'idx_grant_type');
        });
    }

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