<?php

declare(strict_types=1);

namespace App\Models;

use CodeIgniter\Model;

class BookingShiftModel extends Model
{
    protected $table            = 'booking_shifts';
    protected $primaryKey       = 'id';
    protected $useAutoIncrement = true;
    protected $returnType       = 'array';
    protected $useSoftDeletes   = false;
    protected $allowedFields    = [
        'schedule_id',
        'shift_start',
        'shift_end',
        'sort_order',
    ];
    protected $useTimestamps    = true;
    protected $createdField     = 'created_at';
    protected $updatedField     = 'updated_at';
    protected $validationRules  = [];

    protected function initialize()
    {
        $this->orderBy('sort_order', 'ASC');
        $this->orderBy('shift_start', 'ASC');
    }

    public function getForSchedule(int $sid): array
    {
        return $this->where('schedule_id', $sid)
                    ->orderBy('sort_order', 'ASC')
                    ->orderBy('shift_start', 'ASC')
                    ->findAll();
    }
}
