<?php

namespace App\Http\Requests\Admin\AcademicClasses;

use App\Enums\DayOfWeek;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class ScheduleRequest extends FormRequest
{
    public function authorize(): bool
    {
        return $this->user()->can($this->isMethod('post') ? 'create-schedules' : 'update-schedules');
    }

    public function rules(): array
    {
        return [
            'course_class_id' => ['required', 'integer', Rule::exists('course_classes', 'id')],
            'day_of_week' => ['required', 'string', Rule::enum(DayOfWeek::class)],
            'start_time' => ['required', 'date_format:H:i'],
            'end_time' => ['required', 'date_format:H:i', 'after:start_time'],
            'room' => ['nullable', 'string', 'max:20'],
            'online_link' => ['nullable', 'string', 'max:255', 'url'],
        ];
    }
}
