<?php

namespace App\Http\Requests\Api\App\Auth;
use App\Http\Requests\Api\ApiMasterRequest;
use Illuminate\Validation\Rule;

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

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array<string, mixed>
     */
    public function rules()
    {
        return [
            "phone_code" => "required|exists:countries,phone_code",
            "phone"        => [
                "required",
                Rule::unique("users")->ignore($this->old_phone, 'phone')->where(function ($query) {
                    return $query->where(["user_type" => "client","phone_code" => $this->phone_code]);
                })
            ],
            "old_phone_code" => "required|exists:countries,phone_code",
            "old_phone"        => [
                "required",
                "exists:users,phone"
            ],
        ];
    }
}
