<?php

namespace App\Domain\Training\Models;

use App\Domain\Identity\Models\Branch;
use App\Domain\Shared\Traits\BelongsToAcademy;
use App\Domain\Training\Enums\HolidayAffects;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class Holiday extends Model
{
    use BelongsToAcademy;

    protected $fillable = [
        'academy_id', 'branch_id', 'name', 'name_ar',
        'date', 'is_recurring', 'affects',
    ];

    protected $casts = [
        'date' => 'date',
        'is_recurring' => 'boolean',
        'affects' => HolidayAffects::class,
    ];

    public function branch(): BelongsTo
    {
        return $this->belongsTo(Branch::class);
    }

    public function scopeOnDate($query, $date)
    {
        return $query->where('date', $date);
    }

    public function scopeAffectsTraining($query)
    {
        return $query->whereIn('affects', [HolidayAffects::All->value, HolidayAffects::Training->value]);
    }
}
