<?php
declare(strict_types=1);

namespace App\Modules\PlaygroundAdmin\Models;

use App\Core\Model;

final class PlaygroundScheduleSlot extends Model
{
    protected string $table = 'playground_schedule_slots';
    protected bool $timestamps = true;

    protected array $fillable = [
        'schedule_id', 'slot_date', 'slot_hour', 'row_number',
        'coach_id', 'academy_id', 'group_type', 'max_trainees',
        'age_group_ar', 'gender', 'notes',
    ];

    public static function getForDateAndHour(int $scheduleId, string $date, string $hour): array
    {
        $db = \App\Core\App::getInstance()->db();
        return $db->select(
            "SELECT pss.*, c.name_ar as coach_name, a.name_ar as academy_name
             FROM playground_schedule_slots pss
             LEFT JOIN coaches c ON c.id = pss.coach_id
             LEFT JOIN academies a ON a.id = pss.academy_id
             WHERE pss.schedule_id = ? AND pss.slot_date = ? AND pss.slot_hour = ?
             ORDER BY pss.row_number",
            [$scheduleId, $date, $hour]
        );
    }

    public static function getForDate(int $scheduleId, string $date): array
    {
        $db = \App\Core\App::getInstance()->db();
        return $db->select(
            "SELECT pss.*, c.name_ar as coach_name, a.name_ar as academy_name
             FROM playground_schedule_slots pss
             LEFT JOIN coaches c ON c.id = pss.coach_id
             LEFT JOIN academies a ON a.id = pss.academy_id
             WHERE pss.schedule_id = ? AND pss.slot_date = ?
             ORDER BY pss.slot_hour, pss.row_number",
            [$scheduleId, $date]
        );
    }
}
