<?php

namespace Modules\SpecialAttendance\Entities;

use App\Models\User;
use App\Models\Traits\BranchTrait;
use App\Models\Traits\CompanyTrait;
use App\Models\Hrm\Attendance\Holiday;
use App\Models\Hrm\Leave\LeaveRequest;
use Illuminate\Database\Eloquent\Model;
use App\Models\Hrm\Attendance\Attendance;
use App\Models\Hrm\Attendance\DutySchedule;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class DutyCalendar extends Model
{
    use HasFactory, CompanyTrait, BranchTrait;

    protected $guarded = ['id'];

    public function employee(): BelongsTo
    {
        return $this->belongsTo(User::class, 'employee_id', 'id');
    }

    public function dutySchedule(): BelongsTo
    {
        return $this->belongsTo(DutySchedule::class, 'duty_schedule_id', 'id');
    }

    public function holiday(): BelongsTo
    {
        return $this->belongsTo(Holiday::class, 'holiday_id', 'id');
    }

    public function leave(): BelongsTo
    {
        return $this->belongsTo(LeaveRequest::class, 'leave_id', 'id');
    }

    public function attendance(): HasOne
    {
        return $this->hasOne(Attendance::class, 'duty_calendar_id', 'id');
    }

    public function attendances(): HasMany
    {
        return $this->hasMany(Attendance::class, 'duty_calendar_id', 'id');
    }

    public function createdBy()
    {
        return $this->belongsTo(User::class, 'created_by');
    }

    public function updatedBy()
    {
        return $this->belongsTo(User::class, 'updated_by');
    }
}
