<?php

namespace app\api\validate;

use think\Validate;

class Account extends Validate
{
    protected $failException = true;
    
    protected $rule = [
        'username'      => 'require|regex:^[a-zA-Z][a-zA-Z0-9_]{2,15}$|unique:user',
        'nickname'      => 'require|chsDash',
        'real_name'     => 'require|chs',
        'identity'      => 'require|idCard',
        'identity_img'  => 'require',
        'birthday'      => 'date',
        'email'         => 'require|email|unique:user',
        'mobile'        => 'require|mobile|unique:user',
        'password'      => 'require|regex:^(?!.*[&<>"\'\n\r]).{6,32}$',
        'account'       => 'require',
        'captcha'       => 'require',
        'avatar'        => 'require',
        'license_type'  => 'require',
        'pilot_license' => 'require',
    ];
    
    /**
     * 验证场景
     */
    protected $scene = [
        'edit'             => ['avatar', 'username', 'nickname', 'birthday'],
        'changePassword'   => ['password'],
        'retrievePassword' => ['account', 'captcha', 'password'],
        'realname'         => ['real_name', 'identity', 'identity_img'],
        'certification'    => ['license_type', 'pilot_license'],
        'applyFor'         => ['real_name' ],
    ];
    
    public function __construct()
    {
        $this->field   = [
            'username'      => __('username'),
            'nickname'      => __('nickname'),
            'real_name'     => __('Real name'),
            'identity'      => __('Identity Number'),
            'identity_img'  => __('Identity card image'),
            'birthday'      => __('birthday'),
            'email'         => __('email'),
            'mobile'        => __('mobile'),
            'password'      => __('password'),
            'avatar'        => __('avatar'),
            'license_type'  => __('License type'),
            'pilot_license' => __('License'),
        ];
        $this->message = array_merge($this->message, [
            'nickname.chsDash' => __('nicknameChsDash'),
            'password.regex'   => __('Please input correct password')
        ]);
        parent::__construct();
    }
}