<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class EventImprovedHealthRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        // only allow updates if the user is logged in
        //return backpack_auth()->check();
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'disease_type' => 'required',
            'hospital_name' => 'required|min:2',
            'name' => 'required|min:1|max:128',
            'twid' => 'required|isNI',
            'phone' => 'required|phone:TW',
            'email' => 'required|email',
            'address' => ['required','regex:/^(\d{3})\s+([\p{Han}]{2,4}[縣市])\s+([\p{Han}]{2,4}[鎮鄉市區])\s+([\p{Han}]+[里村])\s+(.+)$/u'],
            'check_reson' => 'required_if:check_state,3',
        ];
    }

    /**
     * Get the validation attributes that apply to the request.
     *
     * @return array
     */
    public function attributes()
    {
        return [
            'disease_type' => '疾病類別',
            'hospital_name' => '就醫院所',
            'name' => '姓名',
            'twid' => '身份證字號',
            'phone' => '行動電話',
            'email' => '電子信箱',
            'address' => '收件地址'
        ];
    }

    /**
     * Get the validation messages that apply to the request.
     *
     * @return array
     */
    public function messages()
    {
        return [
            'twid.is_n_i' => '身份證字號驗證有誤',
            'phone.phone' => '行動電話驗證有誤',
            'address.regex' => '收件地址格式有誤，請確定「縣/市」、「鄉/鎮/市/區」、「村/里」及「地址」是否正確。',
            'check_reson.required_if' => '當審核狀態為「未通過」時，必需填寫「審核回應」欄位'
        ];
    }
}
