package jnpf.model.personnels.vo.black;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.annotation.EnumValue;
import jnpf.easyexcel.EasyEnumNames;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

import java.util.Date;

@RequiredArgsConstructor
@Getter
public enum BlackTermEnum implements EasyEnumNames {
    ONE_MONTH(0, "三个月") {
        @Override
        public Date calculateFailureTime(Date startDate) {
            return DateUtil.offsetMonth(startDate, 3).toJdkDate();
        }
    },
    TWO_MONTH(1, "六个月") {
        @Override
        public Date calculateFailureTime(Date startDate) {
            return DateUtil.offsetMonth(startDate, 6).toJdkDate();
        }
    },
    THREE_MONTH(2, "一年") {
        @Override
        public Date calculateFailureTime(Date startDate) {
            return DateUtil.offsetMonth(startDate, 12).toJdkDate();
        }
    },
    FOUR_YEAR(3, "一年六个月") {
        @Override
        public Date calculateFailureTime(Date startDate) {
            return DateUtil.offsetMonth(startDate, 18).toJdkDate();
        }
    },
    FIVE_YEAR(4, "两年") {
        @Override
        public Date calculateFailureTime(Date startDate) {
            return DateUtil.offsetMonth(startDate, 24).toJdkDate();
        }
    },
    SIX_YEAR(5, "三年") {
        @Override
        public Date calculateFailureTime(Date startDate) {
            return DateUtil.offsetMonth(startDate, 36).toJdkDate();
        }
    },
    SEVEN_YEAR(6, "五年") {
        @Override
        public Date calculateFailureTime(Date startDate) {
            return DateUtil.offsetMonth(startDate, 60).toJdkDate();
        }
    },
    EIGHT_YEAR(7, "永久") {
        @Override
        public Date calculateFailureTime(Date startDate) {
            return null;
        }
    },
    ;

    @EnumValue
    private final Integer code;

    private final String name;

    public abstract Date calculateFailureTime(Date startDate);

    public static BlackTermEnum getByCode(Integer code) {
        for (BlackTermEnum value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        return null;
    }

}
