<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('leave_balances', function (Blueprint $row) {
            $row->id();
            $row->foreignId('user_id')->constrained()->onDelete('cascade');
            $row->foreignId('leave_type_id')->constrained()->onDelete('cascade');
            $row->integer('total_allowance')->default(0);
            $row->decimal('used', 8, 2)->default(0);
            $row->decimal('remaining', 8, 2)->default(0);
            $row->integer('year');
            $row->timestamps();

            $row->unique(['user_id', 'leave_type_id', 'year']);
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('leave_balances');
    }
};
