<?php

namespace App\Http\Requests;

use App\Enums\ClassMethod;
use App\Enums\Gender;
use App\Enums\PaymentMethod;
use App\Enums\Semester;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class PaginatedRequest extends FormRequest
{
    public function authorize(): bool
    {
        return true;
    }

    public function rules(): array
    {
        return [
            'per_page' => ['nullable', 'integer', 'in:25,50,100,999999'],
            'search' => ['nullable', 'string', 'max:255'],
            'highlight' => ['nullable', 'integer'],
            'gender' => ['nullable', 'string', Rule::in(Gender::values())],
            'department_id' => ['nullable', 'integer'],
            'status' => ['nullable', 'string'],
            'enrollment_year' => ['nullable', 'integer'],
            'semester_number' => ['nullable', 'integer'],
            'semester' => ['nullable', 'string', Rule::in(Semester::values())],
            'is_active' => ['nullable', Rule::in(['true', 'false'])],
            'academic_term_id' => ['nullable', 'integer'],
            'method' => ['nullable', 'string', Rule::in(ClassMethod::values())],
            'course_class_id' => ['nullable', 'integer'],
            'lecturer_id' => ['nullable', 'integer'],
            'type' => ['nullable', 'string'],
            'payment_method' => ['nullable', 'string', Rule::in(PaymentMethod::values())],
            'file' => ['nullable', 'string'],
            'level' => ['nullable', 'string'],
        ];
    }

    public function validatedWithDefaults(): array
    {
        $validated = $this->validated();

        return [
            'perPage' => $validated['per_page'] ?? 25,
            'search' => $validated['search'] ?? '',
        ];
    }
}
