package com.sckw.core.model.enums;

import com.sckw.core.model.constant.NumberConstant;
import lombok.Getter;

import java.util.ArrayList;
import java.util.List;

/**
 * @author lfdc
 * @description 物流订单-单据状态
 * @date 2023-07-07 14:07:23
 */
@Getter
public enum LogisticsOrderEnum {
    /**
     * 物流订单-待签约
     */
    TO_BE_PLANNED(0, "waitingSigning", "0", "待签约"),
    /**
     * 物流订单-待接单
     */
    PENDING_ORDER(1, "pendingOrder", "1", "待接单"),
    /**
     * 物流订单-待派车
     */
    WAIT_DELIVERY(2, "waitDelivery", "2", "待派车"),
    /**
     * 物流订单-运输中
     */
    IN_TRANSIT(3, "inTransit", "3", "运输中"),
    /**
     * 物流订单-已完成
     */
    //    WAIT_LOADING(4, "waitLoading", "4", "待装货"),
//    WAIT_UNLOADING(5, "waitUnLoading", "5", "待卸货"),
    HAVE_FINISHED(4, "haveFinished", "4", "已完成"),
    /**
     * 物流订单-已对账
     */
    HAVE_RECONCILED(5, "haveReconciled", "5", "已对账"),
    /**
     * 物流订单-已结算
     */
    HAVE_ALREADY_SETTLED(6, "haveAlreadySettled", "6", "已结算"),
    /**
     * 物流订单-已退回
     */
    SEND_BACK(7, "sendBack", "7", "已退回"),

    REJECT_ORDER(8, "rejectOrder", "8", "已拒单"),

    CANCEL_ORDER(9, "cancelOrder", "9", "已撤销"),
    ;

    private final Integer code;
    private final String value;
    private final String status;
    private final String destination;

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public String getStatus() {
        return status;
    }

    public String getDestination() {
        return destination;
    }

    LogisticsOrderEnum(Integer code, String value, String status, String destination) {
        this.code = code;
        this.value = value;
        this.status = status;
        this.destination = destination;
    }

    public static String getLogisticsOrderValue(Integer code) {
        for (LogisticsOrderEnum logisticsOrderEnum : LogisticsOrderEnum.values()) {
            if (logisticsOrderEnum.getCode().equals(code)) {
                return logisticsOrderEnum.getValue();
            }
        }
        return null;
    }

    public static String getName(Integer code) {
        for (LogisticsOrderEnum logisticsOrderEnum : LogisticsOrderEnum.values()) {
            if (logisticsOrderEnum.getCode().equals(code)) {
                return logisticsOrderEnum.getDestination();
            }
        }
        return null;
    }

    public static List<Integer> getCodeList() {
        List<Integer> codeList = new ArrayList<>(NumberConstant.SIXTEEN);
        for (LogisticsOrderEnum value : LogisticsOrderEnum.values()) {
            codeList.add(value.getCode());
        }
        return codeList;
    }

    /**
     * 获取所有的状态
     *
     * @return
     */
    public static List<String> getCodeStringList() {
        List<String> codeList = new ArrayList<>(NumberConstant.SIXTEEN);
        for (LogisticsOrderEnum value : LogisticsOrderEnum.values()) {
            codeList.add(value.getStatus());
        }
        return codeList;
    }


    public static String getDestination(String status) {
        for (LogisticsOrderEnum logisticsOrderEnum : LogisticsOrderEnum.values()) {
            if (logisticsOrderEnum.getStatus().equals(status)) {
                return logisticsOrderEnum.getDestination();
            }
        }
        return null;
    }

    public static LogisticsOrderEnum getLogisticsOrderEnumByCode(Integer code) {
        for (LogisticsOrderEnum logisticsOrderEnum : LogisticsOrderEnum.values()) {
            if (logisticsOrderEnum.getCode().equals(code)) {
                return logisticsOrderEnum;
            }
        }
        return null;
    }

    public static LogisticsOrderEnum getEntityByCode(Integer code) {
        for (LogisticsOrderEnum logisticsOrderEnum : LogisticsOrderEnum.values()) {
            if (logisticsOrderEnum.getCode().equals(code)) {
                return logisticsOrderEnum;
            }
        }
        return null;
    }

    /**
     * @param status 物流订单状态
     * @description 校验物流订单是否运输完成
     * @author zk
     * @date 2023/7/31
     **/
    public static boolean transportCompleted(int status) {
        if (status != LogisticsOrderEnum.HAVE_FINISHED.getCode()
                && status != LogisticsOrderEnum.HAVE_RECONCILED.getCode()
                && status != LogisticsOrderEnum.HAVE_ALREADY_SETTLED.getCode()) {
            return false;
        }
        return true;
    }


    /**
     * 获取编码以及注释
     *
     * @return
     */
    public static String getCodeAndDestination() {
        StringBuilder sb = new StringBuilder();
        for (LogisticsOrderEnum value : LogisticsOrderEnum.values()) {
            sb.append(value.getCode()+":").append(value.destination).append(";");
        }
        return sb.toString();
    }

    public static void main(String[] args) {
        String codeAndDestination = getCodeAndDestination();
        System.out.println(codeAndDestination);
    }
}
