<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

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'],
            'sort' => ['nullable', 'string'],
            'direction' => ['nullable', 'string', 'in:asc,desc'],
            'highlight' => ['nullable', 'integer'],
        ];
    }

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

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