<?php

namespace App\Http\Requests\Admin\UserManagement;

use Illuminate\Contracts\Validation\ValidationRule;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class UpdateRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     */
    public function authorize(): bool
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, ValidationRule|array|string>
     */
    public function rules(): array
    {
        return [
            'full_name' => 'required|max:255|string',
            'username' => ['required', 'string', Rule::unique('users', 'username')->ignore($this->user->id)],
            'position' => 'required',
            'gender' => 'required|in:male,female',
            'national_id' => ['required', 'digits:10', Rule::unique('users', 'national_id')->ignore($this->user->id)],
            'phone_number' => ['required',
                'numeric',
                'digits:11',
                Rule::unique('users', 'phone_number')->ignore($this->user->id),
                'regex:/^09\d{9}$/'
            ],
            'province_id' => 'required|exists:provinces,id',
            'role_id' => 'required|exists:roles,id',
            'avatar' => 'mimes:png,jpg,pdf|max:2048',
            'email' => ['email', Rule::unique('users', 'email')->ignore($this->user->id)],
            'telephone_id' => ['required', 'numeric', Rule::unique('users', 'telephone_id')->ignore($this->user->id)],
        ];
    }
}
