'use strict';

// eslint-disable-next-line node/no-extraneous-import
import { ComoRules } from "como-ts-utils";
import { ComoValidatorRuleType, ComoValidatorTimingType, GlobalOjectType } from "../interface";
import { BaseValidatePipe, QuickRuleOccasion } from "./BaseValidatePipe";


export class QuickValidatePipe extends BaseValidatePipe<GlobalOjectType,GlobalOjectType> {
    /**
     * 动态写入字段
     */
    protected _asyncFiels:{
        [field:string]:ComoValidatorTimingType
    } = {};

    /**
     * 动态添加字段
     * @param field
     * @param rule
     * @param timming 1必须验证 2存在就验证 3值不为空时验证
     * @returns
     */
    Rule(field:string,rule:ComoRules,timming?:1|2|3) {
        this._asyncFiels[field] = {
            validaRule:rule,
            validaTiming:timming ?? QuickRuleOccasion.required
        };
        return this;
    }
    /**
     * 按方法级别进行验证
     * @param methodName
     */
    // eslint-disable-next-line @typescript-eslint/no-unused-vars
    Validate(methodName:string):ComoValidatorRuleType {
        return this._asyncFiels;
    }
    /**
     * 获取实例
     */
    static get Ins() {
        return new this;
    }
}