package com.ningdatech.pmapi.leave.entity.enumeration;

import lombok.Getter;

import java.util.Arrays;

/**
 * <p>
 * LeaveStatus
 * </p>
 *
 * @author WendyYang
 * @since 09:39 2022/8/12
 */
@Getter
public enum LeaveStatusEnum {

    /**
     * 请假状态
     */
    APPLYING(1, "审核中"),
    PASSED(2, "审核通过"),
    PASSED_END(3, "审核通过且销假"),
    UN_PASSED(4, "审核不通过"),
    CANCELED(5, "发起人撤销");
    private final Integer code;
    private final String name;

    public boolean eq(Integer code) {
        return this.getCode().equals(code);
    }

    LeaveStatusEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public static LeaveStatusEnum getByCode(Integer code) {
        return Arrays.stream(values())
                .filter(w -> w.getCode().equals(code))
                .findFirst()
                .orElseThrow(() -> new IllegalArgumentException("无效的请假状态"));
    }

}
