<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Auth;
use Illuminate\Validation\Rules\Password;

class UserEdit extends FormRequest
{
	/**
	 * Determine if the user is authorized to make this request.
	 */
	public function authorize(): bool
	{
		return Auth::id() === $this->route('o')->id;
	}

	/**
	 * Get the validation rules that apply to the request.
	 *
	 * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
	 */
	public function rules(): array
	{
		return [
			'email'=>'required|email|min:5',
			'password'=>['nullable','confirmed',Password::min(8)],
			'firstname'=>'required|min:2',
			'lastname'=>'required|min:2',
			'address1'=>'required|min:8',
			'address2'=>'nullable|min:8',
			'city'=>'required|min:4',
			'state'=>'required|min:3|max:3',
			'postcode'=>'required|min:4|max:4',
			'country_id'=>'required|exists:countries,id'
		];
	}
}