<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class LeaveBalance extends Model
{
    protected $fillable = [
        'employee_id','leave_type_id','year',
        'entitled_days','taken_days','pending_days',
    ];

    public function employee()  { return $this->belongsTo(Employee::class); }
    public function leaveType() { return $this->belongsTo(LeaveType::class); }

    public function getRemainingAttribute(): int
    {
        return max(0, $this->entitled_days - $this->taken_days - $this->pending_days);
    }
}
