<?php

namespace App\Modules\HR\Leave\Models;

use App\Modules\Admin\Tenancy\Traits\BelongsToTenant;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;

class LeaveType extends Model
{
    use BelongsToTenant;
    use SoftDeletes;

    protected $fillable = [
        'tenant_id',
        'name',
        'is_paid',
        'annual_limit',
        'requires_approval',
        'allow_half_day',
        'allow_negative_balance',
        'requires_attachment',
        'allow_carry_forward',
        'carry_forward_max_days',
        'allow_hourly',
        'max_hourly_hours',
        'is_active',
    ];

    protected function casts(): array
    {
        return [
            'is_paid' => 'boolean',
            'requires_approval' => 'boolean',
            'allow_half_day' => 'boolean',
            'allow_negative_balance' => 'boolean',
            'requires_attachment' => 'boolean',
            'allow_carry_forward' => 'boolean',
            'carry_forward_max_days' => 'decimal:2',
            'allow_hourly' => 'boolean',
            'max_hourly_hours' => 'decimal:2',
            'is_active' => 'boolean',
        ];
    }

    public function leaveRequests(): HasMany
    {
        return $this->hasMany(LeaveRequest::class);
    }
}
