package com.cf.imes.module.system.validation.user;

import cn.hutool.core.util.ObjectUtil;
import com.cf.imes.module.system.enums.common.SexEnum;

import jakarta.validation.ConstraintValidator;
import jakarta.validation.ConstraintValidatorContext;
import java.util.Objects;

/**
 * 性别校验器
 *
 * @author Gqr
 * @since 2024/10/12 9:50
 */
public class SexValidator implements ConstraintValidator<SexValid, Integer> {

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext context) {
        if (ObjectUtil.isNull(value)) {
            return true;
        }
        for (SexEnum sexEnum : SexEnum.values()) {
            if (Objects.equals(sexEnum.getSex(), value)) {
                return true;
            }
        }
        return false;
    }
}
