<?php
declare(strict_types=1);

namespace App\Modules\PlaygroundAdmin\Models;

use App\Core\Model;

final class PlaygroundMonthlySchedule extends Model
{
    protected string $table = 'playground_monthly_schedules';
    protected bool $timestamps = true;

    protected array $fillable = [
        'playground_id', 'plan_month', 'plan_name_ar', 'status',
        'working_days_json', 'day_start_time', 'day_end_time',
        'notes', 'created_by', 'activated_at',
    ];

    public static function getForPlayground(int $playgroundId): array
    {
        $db = \App\Core\App::getInstance()->db();
        return $db->select(
            "SELECT * FROM playground_monthly_schedules WHERE playground_id = ? ORDER BY plan_month DESC",
            [$playgroundId]
        );
    }

    public function getWorkingHours(): array
    {
        $start = strtotime($this->day_start_time ?? '07:00');
        $end = strtotime($this->day_end_time ?? '22:00');
        $hours = [];

        while ($start < $end) {
            $hours[] = date('H:i', $start);
            $start += 3600;
        }

        return $hours;
    }
}
