package com.fzm.mall.server.admin.config;

import com.fzm.mall.server.admin.annotation.CustomType;
import com.fzm.mall.server.admin.auth_center.enums.type.AdminRoleTypeEnum;
import com.fzm.mall.server.admin.constant.MALLGlobalConfig;
import com.fzm.mall.server.admin.finance_center.enums.status.MerchantIntegralStatusEnum;
import com.fzm.mall.server.admin.finance_center.enums.type.MerchantIntegralTypeEnum;
import com.fzm.mall.server.admin.finance_center.enums.type.PayModeTypeEnum;
import com.fzm.mall.server.admin.finance_center.enums.type.TranObjectEnum;
import com.fzm.mall.server.admin.goods_center.enums.status.SpuStatusEnum;
import com.fzm.mall.server.admin.goods_center.enums.type.GoodsTypeEnum;
import com.fzm.mall.server.admin.goods_center.enums.type.ReturnGoodsTypeEnum;
import com.fzm.mall.server.admin.home_page.enums.status.MerchantRegisterEnum;
import com.fzm.mall.server.admin.home_page.enums.type.AdminTypeEnum;
import com.fzm.mall.server.admin.home_page.enums.type.MerchantTypeEnum;
import com.fzm.mall.server.admin.home_page.enums.type.RepairPwdTypeEnum;
import com.fzm.mall.server.admin.message.enums.type.AddresseeTypeEnum;
import com.fzm.mall.server.admin.message.enums.type.SendTypeEnum;
import com.fzm.mall.server.admin.user_center.enums.status.UserLockStatusEnum;
import com.fzm.mall.server.admin.user_center.enums.type.MemberLevelTypeEnum;
import com.fzm.mall.server.admin.user_center.enums.type.MerchantLevelTypeEnum;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.ArrayList;
import java.util.List;

/**
 * @author wangp
 * @date 2021/3/8 13:51
 * @description
 * @since JDK 1.8
 */
public class MyConstraintValidator implements ConstraintValidator<CustomType, Integer> {

    private int pType;

    @Override
    public void initialize(CustomType constraintAnnotation) {
        pType = constraintAnnotation.pType();

    }

    @Override
    public boolean isValid(Integer o, ConstraintValidatorContext constraintValidatorContext) {
        List<Integer> types = new ArrayList<>();

        switch (pType) {
            case MALLGlobalConfig.REPAIR_PWD:
                types = RepairPwdTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.ENTERPRISE_TYPE:
                types = MerchantTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.GOODS_TYPE:
                types = GoodsTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.RETURN_TYPE:
                types = ReturnGoodsTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.GOODS_STATUS:
                types = SpuStatusEnum.getValueList();
                break;
            case MALLGlobalConfig.GOODS_CHECK_STATUS:
                types = SpuStatusEnum.getCheckValueList();
                break;
            case MALLGlobalConfig.USER_LOCK:
                types = UserLockStatusEnum.getValueList();
                break;
            case MALLGlobalConfig.MEMBER_SHIP:
                types = MemberLevelTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.MERCHANT_SHIP:
                types = MerchantLevelTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.MERCHANT_LOCK:
                types = MerchantRegisterEnum.getLockValueList();
                break;
            case MALLGlobalConfig.MERCHANT_CHECK:
                types = MerchantRegisterEnum.getCheckValueList();
                break;
            case MALLGlobalConfig.ON_OFF:
                types = SpuStatusEnum.getOnOffList();
                break;
            case MALLGlobalConfig.PAY_MODE:
                types = PayModeTypeEnum.getPayModeList();
                break;
            case MALLGlobalConfig.INTEGRAL_CHECK:
                types = MerchantIntegralStatusEnum.getIntegralCheckList();
                break;
            case MALLGlobalConfig.INTEGRAL_DISABLE:
                types = MerchantIntegralStatusEnum.getIntegralDisableList();
                break;
            case MALLGlobalConfig.SEND_TYPE:
                types = SendTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.ADDRESSEE_TYPE:
                types = AddresseeTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.INTEGRAL_TYPE:
                types = MerchantIntegralTypeEnum.getValueList();
                break;
            case MALLGlobalConfig.TRAN_OBJECT:
                types = TranObjectEnum.getValueList();
                break;
            case MALLGlobalConfig.ROLE_TYPE:
                types = AdminRoleTypeEnum.getValueList();
                break;
        }

        boolean res = false;
        for (Integer type : types) {
            if (type.equals(o)) {
                res = true;
                break;
            }
        }
        return res;
    }
}
