<?php

declare(strict_types=1);

namespace App\Request;

use App\Constants\HttpEnumCode;
use Hyperf\Validation\Contract\ValidatorFactoryInterface;
use Hyperf\Validation\Request\FormRequest;
use Hyperf\Validation\Rule;

class PatientFamilyRequest extends FormRequest
{
    /**
     * @Inject
     * @var ValidatorFactoryInterface
     */
    protected ValidatorFactoryInterface $validationFactory;

    protected array $scenes = [
        'addFamily' => [ // 新增家庭成员
            'relation',
            'is_default',
            'card_name',
            'mobile',
            'type',
            'id_number',
            'province_id',
            'city_id',
            'county_id',
            'height',
            'weight',
            'marital_status',
        ],
        'editFamily' => [ // 修改家庭成员
            'relation',
            'is_default',
            'card_name',
            'type',
            'id_number',
            'province_id',
            'city_id',
            'county_id',
            'height',
            'weight',
            'marital_status',
        ],
        'editFamilyPersonal' => [ // 修改家庭成员-个人情况
            'is_allergy_history',// 过敏史
            'allergy_history',
            'is_family_history', // 家族病史
            'family_history',
            'is_pregnant',// 备孕、妊娠、哺乳期
            'pregnant',
            'is_operation', // 是否存在手术（0:否 1:是）
            'operation',
            'drink_wine_status', // 饮酒状态（1:从不 2:偶尔 3:经常 4:每天 5:已戒酒）
            'smoke_status',// 吸烟状态（1:从不 2:偶尔 3:经常 4:每天 5:已戒烟）
            'chemical_compound_status', // 化合物状态（1:从不 2:偶尔 3:经常 4:每天）
            'chemical_compound_describe',
        ],
        'addFamilyPersonal' => [ // 新增家庭成员-个人情况
            'family_id',
            'is_allergy_history',// 过敏史
            'allergy_history',
            'is_family_history', // 家族病史
            'family_history',
            'is_pregnant',// 备孕、妊娠、哺乳期
            'pregnant',
            'is_operation', // 是否存在手术（0:否 1:是）
            'operation',
            'drink_wine_status', // 饮酒状态（1:从不 2:偶尔 3:经常 4:每天 5:已戒酒）
            'smoke_status',// 吸烟状态（1:从不 2:偶尔 3:经常 4:每天 5:已戒烟）
            'chemical_compound_status', // 化合物状态（1:从不 2:偶尔 3:经常 4:每天）
            'chemical_compound_describe',
        ],
        'editFamilyHealth' => [ // 修改家庭成员-健康情况
            'disease_class_id',
            'diagnosis_date',// 确诊日期
            'diagnosis_hospital',//确诊医院
            'drugs_name', // 家族病史
        ],
        'addFamilyHealth' => [ // 新增家庭成员-健康情况
            'family_id',
            'disease_class_id',
            'diagnosis_date',// 确诊日期
            'diagnosis_hospital',//确诊医院
            'drugs_name', // 家族病史
        ],
    ];

    /**
     * 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.
     */
    public function rules(): array
    {
        return [
            'card_name' => 'required',
            'type' => ['required',Rule::in(['1', '2', '3', '4'])],
            'id_number' => "required",
            'mobile' => ['sometimes','regex:/^1(3\d|4[5-9]|5[0-35-9]|6[2567]|7[0-8]|8\d|9[0-35-9])\d{8}$/'],
            'relation' => ['sometimes',Rule::in(['1', '2', '3', '4', '5', '6'])],
            'city_id' => 'required_with:province_id',
            'province_id' => 'required_with:city_id',
            'is_default' => ['sometimes',Rule::in(['0', '1'])],
            'height' => ['sometimes','numeric'], // 身高
            'weight' => ['sometimes','numeric'], // 体重
            'marital_status' => ['sometimes',Rule::in(['0', '1'])], // 婚姻状况(0:未婚 1:已婚)
            'is_allergy_history' => ['sometimes','numeric','min:0','max:1'],
            'is_family_history' => ['sometimes','numeric','min:0','max:1'],
            'is_pregnant' => ['sometimes','numeric','min:0','max:1'],
            'is_operation' => ['sometimes','numeric','min:0','max:1'],
            'drink_wine_status' => ['sometimes','numeric','min:1','max:5'],
            'smoke_status' => ['sometimes','numeric','min:1','max:5'],
            'chemical_compound_status' => ['sometimes','numeric','min:1','max:4'],
            'family_id' => "required",
            'disease_class_id' => "required",
            'diagnosis_date' => ['sometimes','date'],
        ];
    }

    /**
     * 获取已定义验证规则的错误消息.
     */
    public function messages(): array
    {
        return [
            'name.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'type.required' => "请选择证件类型",
            'type.in' => "证件类型错误",
            'id_number.required' => "请选择证件号",
//            'mobile.required' => "手机号不能为空",
            'mobile.regex' => "手机号格式错误",
            'relation.in' => "患者关系错误",
            'city_id.required_with' => "请选择城市",
            'province_id.required_with' => "请选择省份",
            'is_default.in' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'height.numeric' => "身高错误",
            'weight.numeric' => "体重错误",
            'blood_type.in' => "血型错误",
            'marital_status.in' => "婚姻状况错误",
            'is_allergy_history.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_allergy_history.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_allergy_history.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_family_history.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_family_history.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_family_history.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_pregnant.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_pregnant.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_pregnant.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_operation.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_operation.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'is_operation.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'drink_wine_status.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'drink_wine_status.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'drink_wine_status.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'smoke_status.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'smoke_status.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'smoke_status.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'chemical_compound_status.numeric' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'chemical_compound_status.min' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'chemical_compound_status.max' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'family_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'disease_class_id.required' => HttpEnumCode::getMessage(HttpEnumCode::CLIENT_HTTP_ERROR),
            'diagnosis_date.date' => "日期格式错误",
        ];
    }
}
