<?php

declare(strict_types=1);

namespace App\Models;

use CodeIgniter\Model;

class BookingScheduleExceptionModel extends Model
{
    protected $table            = 'booking_schedule_exceptions';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $allowedFields    = [
        'schedule_id',
        'exception_date',
        'is_closed',
        'custom_open',
        'custom_close',
        'note',
    ];
    protected $useTimestamps    = true;
    protected $createdField     = 'created_at';
    protected $updatedField     = 'updated_at';
    protected $validationRules  = [];

    public function getForScheduleBetween(int $scheduleId, string $dateStart, string $dateEnd): array
    {
        return $this->where('schedule_id', $scheduleId)
                    ->where('exception_date >=', $dateStart)
                    ->where('exception_date <=', $dateEnd)
                    ->orderBy('exception_date', 'ASC')
                    ->findAll();
    }
}
