<?php

namespace App\Http\Requests;

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

class MemberStore extends FormRequest
{
    use SanitizesInput;

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules(): array
    {
        $rules = [];

        $rules = array_merge($rules, [
            'name'                  => 'required|max:250',
            'notes'                 => 'nullable',
            'member_type'           => 'required|max:10',
            'state'                 => 'required|max:100',
            'logo_id'               => 'nullable',
            'country_id'            => 'required|integer',
            'legal_committee'       => 'nullable',
            'legal_opinions'        => 'nullable',
            'user_permission_level' => 'nullable',
            'wg'                    => 'nullable|array',
            'domain'                => 'nullable|array',
            'domain.*'              => [
                'string',
                // Rule::unique('domains', 'domain'),
                'regex:/^(?!:\/\/)(?=.{1,255}$)((.{1,63}\.){1,127}(?![0-9]*$)[a-z0-9-]+\.?)$/i',
                // 'regex:/^[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/u'
            ],
        ]);

        return $rules;
    }

    /**
     * Filters to be applied to the input.
     *
     * @return array
     */
    public function filters(): array
    {
        return [
            'name'                  => "trim|strip_tags|xss_clean",
            'notes'                 => "trim|strip_tags|xss_clean",
            'member_type'           => "trim|strip_tags|xss_clean",
            'state'                 => "trim|strip_tags|xss_clean",
            'logo_id'               => "trim|strip_tags|xss_clean",
            'country_id'            => "trim|strip_tags|xss_clean",
            'legal_committee'       => "trim|strip_tags|xss_clean",
            'legal_opinions'        => "trim|strip_tags|xss_clean",
            'user_permission_level' => "trim|strip_tags|xss_clean",
        ];
    }
}
