package com.sckw.core.model.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@AllArgsConstructor
@Getter
public enum OrderUsualStatusEnum {
    HAVE_BEEN_SAVED(1, "已保存"),
    UNDER_REVIEW(3, "审核中"),
    WAIT_TRANSPORT(5, "待运输"),
    IN_TRANSIT(7, "运输中"),
    FINISHED(9, "已完成"),
    RECONCILED(11, "待对账"),
    WAIT_SETTLED(13, "待结算"),
    FINISH_SETTLED(15, "已结算"),
    CANCELLED(17, "已取消"),
    RETURNED(19, "已退回")
            ;

    private final Integer code;
    private final String msg;


    public static String getNameByCode(Integer code) {
        OrderUsualStatusEnum[] enums = OrderUsualStatusEnum.values();
        for (OrderUsualStatusEnum instance : enums) {
            if (Objects.equals(instance.getCode(), code)) {
                return instance.getMsg();
            }
        }
        return null;
    }

    public static List<OrderUsualStatusEnum> getSortList() {
        OrderUsualStatusEnum[] enums = OrderUsualStatusEnum.values();
        return Arrays.stream(enums).sorted(Comparator.comparingInt(OrderUsualStatusEnum::getCode)).collect(Collectors.toList());
    }
}
