<?php

namespace App\Http\Requests\Backoffice;

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

class CompanyProfileCreateUpdateRequest extends FormRequest
{
    use SanitizesInput;

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        $profileId = $this->route('profileId');

        return [
            'accountId' => [
                'nullable',
                'integer',
                'exists:accounts,id',
                Rule::unique('company_profiles', 'account_id')->ignore($profileId),
            ],
            'name' => 'required|max:255',
            'employeeCount' => 'nullable|max:10',
            'email' => 'nullable|email|max:255',
            'phonePrefix' => 'nullable|max:10',
            'phone' => 'nullable|max:20',
            'websiteUrl' => 'nullable|url|max:255',
            'subtitle' => 'nullable|max:255',
            'location' => 'nullable|max:255',
            'description' => 'nullable|string',
            'instagramUrl' => 'nullable|url|max:255',
            'linkedinUrl' => 'nullable|url|max:255',
            'facebookUrl' => 'nullable|url|max:255',
            'isActive' => 'required|boolean',
            'isCoverImageUpdated' => 'nullable|boolean',
            'coverImage' => 'nullable|file|image|max:4000',
            'isCompanyImageUpdated' => 'nullable|boolean',
            'companyImage' => 'nullable|file|image|max:4000',
            'specialisationIds' => 'nullable|array',
            'specialisationIds.*' => 'required|integer|exists:company_specialisations,id',
        ];
    }

    public function filters(): array
    {
        return [
            'name' => 'trim|strip_tags|xss_clean',
            'employeeCount' => 'trim|strip_tags|xss_clean',
            'email' => 'trim|strip_tags|xss_clean',
            'phonePrefix' => 'trim|strip_tags|xss_clean',
            'phone' => 'trim|strip_tags|xss_clean',
            'websiteUrl' => 'trim|strip_tags|xss_clean',
            'subtitle' => 'trim|strip_tags|xss_clean',
            'location' => 'trim|strip_tags|xss_clean',
            'instagramUrl' => 'trim|strip_tags|xss_clean',
            'linkedinUrl' => 'trim|strip_tags|xss_clean',
            'facebookUrl' => 'trim|strip_tags|xss_clean',
        ];
    }
}
