<?php

namespace App\Http\Requests\ClassProgress;

use App\Http\Requests\ClassProgress\ClassProgressFormRequest;

class ClassProgressIndexRequest extends ClassProgressFormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        $statuses = array_keys((array) config('progress.status_options', []));

        return [
            'class_section_id' => ['nullable', 'integer', 'min:1'],
            'teacher_id' => ['nullable', 'integer', 'min:1'],
            'school_year' => ['nullable', 'string', 'max:20'],
            'semester' => ['nullable', 'string', 'max:20'],
            'week_start' => ['nullable', 'date_format:Y-m-d'],
            'week_end' => ['nullable', 'date_format:Y-m-d'],
            'subject' => ['nullable', 'string', 'max:120'],
            'status' => $statuses ? ['nullable', 'in:' . implode(',', $statuses)] : ['nullable', 'string'],
            'group_by_week' => ['nullable', 'boolean'],
            'page' => ['nullable', 'integer', 'min:1'],
            'per_page' => ['nullable', 'integer', 'min:1', 'max:200'],
            'sort_by' => ['nullable', 'in:week_start,week_end,subject,status,created_at'],
            'sort_dir' => ['nullable', 'in:asc,desc'],
        ];
    }
}
