<?php

namespace App\Http\Requests\Bidding;

use App\Models\Bidding\Bidding;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

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

    public function rules(): array
    {
        return [
            'status' => ['nullable', 'string', Rule::in(Bidding::STATUSES)],
            'from_date' => ['nullable', 'date'],
            'to_date' => ['nullable', 'date', 'after_or_equal:from_date'],
            'search' => ['nullable', 'string', 'max:100'],
            'sort_by' => ['nullable', 'string', Rule::in(['bidding_date', 'bidding_code', 'client_name', 'project_name', 'bidding_amount', 'status', 'created_at'])],
            'sort_dir' => ['nullable', 'string', Rule::in(['asc', 'desc'])],
            'per_page' => ['nullable', 'integer', 'min:1'],
        ];
    }

    public function messages(): array
    {
        return [
            'status.in' => __('validation.in', ['attribute' => __('validation.attributes.status')]),
            'to_date.after_or_equal' => __('validation.after_or_equal', ['attribute' => __('validation.attributes.to_date'), 'date' => __('validation.attributes.from_date')]),
        ];
    }
}
