<?php

namespace App\Http\Requests;

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

class OfficeRequest extends FormRequest
{
    use SanitizesInput;

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'name'         => 'required|string|max:150',
            'address'      => 'required|max:150',
            'floor'        => 'nullable|max:255',
            'postalCode'   => 'required|max:15',
            'location'     => 'required|max:100',
            'linkGoogleMaps' => 'nullable|url|max:255',
            'isMainOffice' => 'required|boolean',
            'countryId'    => 'required|integer|exists:countries,id',
            'phone'        => 'required|max:20',
            'fax'          => 'nullable|max:20',
            'email'        => 'nullable|email|max:255',
            'websiteUrl'   => 'nullable|url|max:255',
        ];
    }

    /**
     * Filters to be applied to the input.
     *
     * @return array
     */
    public function filters(): array
    {
        return [
            'name'         => "trim|strip_tags|xss_clean",
            'address'      => "trim|strip_tags|xss_clean",
            'floor'        => "trim|strip_tags|xss_clean",
            'postalCode'   => "trim|strip_tags|xss_clean",
            'location'     => "trim|strip_tags|xss_clean",
            'linkGoogleMaps' => "trim|strip_tags|xss_clean",
            'isMainOffice' => "trim|strip_tags|xss_clean",
            'countryId'    => "trim|strip_tags|xss_clean",
            'phone'        => "trim|strip_tags|xss_clean",
            'fax'          => "trim|strip_tags|xss_clean",
            'email'        => "trim|strip_tags|xss_clean",
            'websiteUrl'   => "trim|strip_tags|xss_clean",
        ];
    }
}
