package com.rongwei.bsentity.enums;

import lombok.Getter;

import java.util.Objects;
import java.util.stream.Stream;

/**
 * @author shangmi
 * @title TaskStatusEnum
 * @date 2024/1/31 15:08
 * @description 任务状态
 */
@Getter
public enum TaskStatusEnum {
    EXPORT_DISTRIBUTION("10","待派发"),
    UNDER_WAY("30","进行中"),
    CLOSED("40","已关闭"),
    WAIT_ACCEPTANCE("50","待验收"),
    DONE("60","已完成"),
    SPARE_PARTS_READY("70","备件已准备"),
    REWORK_MAINTENANCE("20","返工保养"),
    REWORK_OVERHAUL("80","返工大修")
    ;
    public String code;
    public String massage;

    TaskStatusEnum(String code, String massage) {
        this.code = code;
        this.massage = massage;
    }

    public static String massageOf(String code){
        return getTaskStatusByCode(code,null).massage;
    }

    public static TaskStatusEnum getTaskStatusByCode(String code,TaskStatusEnum taskStatusEnum){
        return Stream.of(values()).filter(info-> Objects.equals(code, info.code)).findFirst().orElse(taskStatusEnum);
    }

    public static String codeOf(String massage){
        return getTaskStatusByMassage(massage,null).code;
    }

    public static TaskStatusEnum getTaskStatusByMassage(String massage,TaskStatusEnum taskStatusEnum){
        return Stream.of(values()).filter(info->massage.equals(info.massage)).findFirst().orElse(taskStatusEnum);
    }
}
