<?php
/**
 * Created by PhpStorm.
 * User: airon
 */

namespace app\common\validate;

use think\Validate;

class Base extends Validate
{
    protected $regex = [
        'mobile' => '1\d{10}'
    ];
    protected $rule = [
        'page_index' => 'require|number|gt:0',
        'page_size' => 'require|number|gt:0',
        'uuid' => 'require|length:32',
        'id' => 'require|number|gt:0',
        'content' => 'require|max:255',
        'mobile' => 'require|number|length:11|regex:mobile',
        'sms_type' => 'require|in:login,bind,pay_password',
        'partner_sms_type' => 'require|in:pass,set_pay,bind_card',
        'code' => 'require|max:6',
        'password' => 'require|min:6',
        'message_type' => 'require|in:con,chat,system',
        'province' => 'chsAlpha',
        'school_name' => 'chsAlpha',
        'city.json' => 'chsAlpha',
        'money' => 'require|number|egt:1',
        'pay_type' => 'require|in:alipay,wechat',
        'nya' => 'in:no,yes,all,,',
        'ny' => 'in:no,yes',
        'tf' => 'in:no,yes,0,1,true,false',
        'id_can_null' => 'number|gt:0',
        'keyword' => 'chsDash',
        'refresh_token' => 'require|length:32',
        'collect_type' => 'require|in:school,speciality',

        'name' => 'require|chsAlphaNum|length:0,64',
        'gender' => 'require|in:男,女',
        'birth' => 'require|chsAlphaNum|length:0,64',
        'avatar' => 'require|chsAlphaNum|length:0,64',
        'city' => 'require|chsAlphaNum|length:0,64',

    ];

    protected $field = [
        'mobile' => '手机号码'
    ];

    protected $message = [
        'page_index' => '页码要大于0',
        'page_size' => '每页数量要大于0',
        'id' => 'id参数不符合',
        'content.require' => '内容不能为空',
        'content.max' => '超出最大长度',
        'mobile.regex' => ':attribute格式错误',
        'sms_type' => '短信类型错误',
        'code' => '验证码格式错误',
        'password.require' => '密码必须',
        'password.min' => '密码过短',
        'message_type' => '消息类型错误',
        'province' => '省份设置错误',
        'city.json' => '城市设置错误',
        'money' => '金额格式不正确',
        'pay_type' => '充值方式不正确',
        'nya' => '参数不正确',
        'ny' => '参数不正确',
        'id_can_null' => '参数不正确',
        'keyword' => '关键字不能带符号',
        'tf' => 'bool错误',
        'collect_type' => '收藏类型',
        'name' => '姓名',
        'gender' => '性别',
        'birth' => '出生年月',
        'avatar' => '头像',
        'city' => '所在地区',
    ];

    protected $scene = [
        'page_index' => ['page_index'],
        'page_size' => ['page_size'],
        'page' => ['page_index', 'page_size'],
        'id' => ['id'],
        'uuid' => ['uuid'],
        'sendSms' => ['mobile', 'sms_type'],

        'sendPartnerSms' => ['mobile', 'sms_type_partner'],
        'validatePartnerCode' => ['mobile', 'sms_type_partner', 'code'],

        'validateCode' => ['mobile', 'sms_type', 'code'],
        'login' => ['mobile', 'code'],
        'bind' => ['mobile', 'code', 'password'],
        'nya' => ['nya'],
        'ny' => ['ny'],
        'id_can_null' => ['id_can_null'],
        'keyword' => ['keyword'],
        'tf' => ['tf'],
        'refresh_token' => ['refresh_token'],
        'feedback' => ['content'],
        'collect_list' => ['collect_type'],
        'cmsLogin' => ['name', 'password'],
        'admissionScore' => ['province','school_name'],

        'batchCritical' => ['province']
    ];

    public function getEnumRule($words)
    {
        $reg = implode('|', $words);
        $rule = "/^({$reg})$/";
        return $rule;
    }

}
