<?php

namespace App\Http\Requests\Localization;

use App\Support\Backoffice\Sanitizer\Traits\SanitizesInput;
use Illuminate\Foundation\Http\FormRequest;

class CountryRequest extends FormRequest
{
    use SanitizesInput;

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'page' => 'nullable|integer',
            'itemsPerPage' => 'nullable|integer|max:250',
            'showSpecialCountriesFirst' => 'nullable|boolean',
            'filter' => 'nullable|array',
            'filter.commonName' => 'nullable|string|max:250',
            'filter.name' => 'nullable|string|max:100',
            'filter.iso2' => 'nullable|string|max:2',
            'filter.iso3' => 'nullable|string|max:3',
        ];
    }

    /**
     * Filters to be applied to the input.
     *
     * @return array
     */
    public function filters(): array
    {
        return [
            'filter.commonName' => "trim|strip_tags|xss_clean",
            'filter.name' => "trim|strip_tags|xss_clean",
            'filter.iso2' => "trim|strip_tags|xss_clean",
            'filter.iso3' => "trim|strip_tags|xss_clean",
            'showSpecialCountriesFirst' => 'trim|strip_tags|xss_clean'
        ];
    }
}
