<?php

namespace App\Http\Requests\Document;

use App\Models\Documents\Document;
use Illuminate\Foundation\Http\FormRequest;

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

    public function rules(): array
    {
        $statuses = implode(',', [
            Document::STATUS_DRAFT,
            Document::STATUS_PENDING,
            Document::STATUS_APPROVED,
            Document::STATUS_REJECTED,
            Document::STATUS_CANCELLED,
        ]);

        return [
            'status' => "nullable|string|in:{$statuses}",
            'template_id' => 'nullable|integer',
            'search' => 'nullable|string|max:100',
            'from_date' => 'nullable|date',
            'to_date' => 'nullable|date|after_or_equal:from_date',
            'sort_by' => 'nullable|string|in:created_at,document_no,title,status,submitted_at,completed_at',
            'sort_dir' => 'nullable|string|in:asc,desc',
            'per_page' => 'nullable|integer|min:1|max:100',
            'page' => 'nullable|integer|min:1',
        ];
    }
}
