package com.sckw.core.model.enums;

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

/**
 * @author lfdc
 * @desc 车辆运单状态枚举
 * @date 2023-07-14 14:07:23
 */
public enum CarWaybillEnum {
    /**
     * 待接单
     */
    PENDING_ORDER(101, "pendingOrder", "101", "待接单", "已指派"),
    /**
     * 已撤销
     */
    REVOKED(102, "revoked", "102", "撤回", "撤回"),
    /**
     * 拒接单
     */
    REJECT_ORDER(103, "rejectOrder", "103", "拒接单", "拒接单"),
    /**
     * 出车-待出车
     */
    PENDING_VEHICLE(201, "pendingVehicle", "201", "待出车", "确认接单"),
    /**
     * 出车-拒出车
     */
    REFUSE_TRAFFIC(202, "refuseTraffic", "202", "拒出车", "拒出车"),
    /**
     * 出车-已出车
     */
    EXIT_COMPLETED(203, "exitCompleted", "203", "已出车", "确认出车"),
    /**
     * 装货-到达装货点
     */
    WAIT_LOADING(301, "waitLoading", "301", "到达装货点", "到达装货点"),
    /**
     * 装货-已装货
     */
    COMPLETION_LOADING(302, "completionLoading", "302", "已装货", "确认装货"),
    /**
     * 卸货-到达卸货点
     */
    WAIT_UNLOADING(401, "waitUnloading", "401", "到达卸货点", "到达卸货点"),
    /**
     * 卸货-已卸货
     */
    COMPLETION_UNLOADING(402, "completionUnloading", "402", "已卸货", "确认卸货"),
    /**
     * 审核-待
     */
    APPROVAL_TREAT(501, "approvalTreat", "501", "待审核", "待审核"),
    /**
     * 审核-通过
     */
    APPROVAL_PASS(502, "approvalPass", "502", "审核通过", "审核通过"),
    /**
     * 审核-驳回
     */
    APPROVAL_NO_PASS(503, "revoked", "503", "核单驳回", "核单驳回"),
    /**
     * 审核-单证更新审核中
     */
    APPROVAL_IN(504, "approvalIn", "504", "单证更新审核中", "单证更新审核中"),
    ;

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

    public Integer getCode() {
        return code;
    }

    public String getValue() {
        return value;
    }

    public String getStatus() {
        return status;
    }

    public String getAlias() {
        return alias;
    }

    public String getDestination() {
        return destination;
    }

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

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

    /**
     *
     * 获取任务中的状态
     * @return 任务中的状态
     */
    public static List<Integer> getTasking() {
        return Arrays.asList(CarWaybillEnum.PENDING_VEHICLE.getCode(),
                CarWaybillEnum.EXIT_COMPLETED.getCode(),
                CarWaybillEnum.WAIT_LOADING.getCode(),
                CarWaybillEnum.COMPLETION_LOADING.getCode(),
                CarWaybillEnum.WAIT_UNLOADING.getCode(),
                CarWaybillEnum.COMPLETION_UNLOADING.getCode());
    }

    public static String getWaybillOrderDestination(String status) {
        for (CarWaybillEnum waybillEnum : CarWaybillEnum.values()) {
            if (waybillEnum.getStatus().equals(status)) {
                return waybillEnum.getDestination();
            }
        }
        return null;
    }

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

    public static String getAlias(Integer code) {
        for (CarWaybillEnum waybillEnum : CarWaybillEnum.values()) {
            if (waybillEnum.getCode().equals(code)) {
                return waybillEnum.getAlias();
            }
        }
        return null;
    }

    public static List<Integer> getCodes() {
        List<Integer> codes = new ArrayList<>();
        for (CarWaybillEnum waybillEnum : CarWaybillEnum.values()) {
            codes.add(waybillEnum.getCode());
        }
        return codes;
    }

    public static List<String> getStringCodes() {
        List<String> codes = new ArrayList<>();
        for (CarWaybillEnum waybillEnum : CarWaybillEnum.values()) {
            codes.add(waybillEnum.getStatus());
        }
        return codes;
    }

    /**
     * @param code 状态码
     * @desc 是否可以变更司机
     * @author zk
     * @date 2023/8/2
     **/
    public static boolean changeDriver(int code) {
        return code != CarWaybillEnum.COMPLETION_UNLOADING.getCode()
                && code != CarWaybillEnum.APPROVAL_PASS.getCode()
                && code != CarWaybillEnum.REJECT_ORDER.getCode()
                && code != CarWaybillEnum.REFUSE_TRAFFIC.getCode()
                && code != CarWaybillEnum.REVOKED.getCode()
                && code != CarWaybillEnum.APPROVAL_NO_PASS.getCode();
    }

    /**
     * @param code 状态码
     * @desc 是否可以变更司机
     * @author zk
     * @date 2023/8/2
     **/
    public static boolean arriveLocation(int code) {
        return code == CarWaybillEnum.EXIT_COMPLETED.getCode()
                || code == CarWaybillEnum.WAIT_LOADING.getCode()
                || code == CarWaybillEnum.COMPLETION_LOADING.getCode()
                || code == CarWaybillEnum.WAIT_UNLOADING.getCode()
                || code == CarWaybillEnum.COMPLETION_UNLOADING.getCode();
    }

    /**
     * @param code 状态码
     * @desc 是否可以变更司机
     * @author zk
     * @date 2023/8/2
     **/
    public static boolean arriveLoading(int code) {
        return code == CarWaybillEnum.WAIT_LOADING.getCode()
                || code == CarWaybillEnum.COMPLETION_LOADING.getCode()
                || code == CarWaybillEnum.WAIT_UNLOADING.getCode()
                || code == CarWaybillEnum.COMPLETION_UNLOADING.getCode()
                || code == CarWaybillEnum.APPROVAL_TREAT.getCode()
                || code == CarWaybillEnum.APPROVAL_NO_PASS.getCode();
    }

    /**
     * @param code 状态码
     * @desc 是否可以变更司机
     * @author zk
     * @date 2023/8/2
     **/
    public static boolean editTicket(int code) {
        return code == CarWaybillEnum.APPROVAL_TREAT.getCode()
                || code == CarWaybillEnum.APPROVAL_NO_PASS.getCode()
                || code == CarWaybillEnum.APPROVAL_IN.getCode() ;
    }

    /**
     * @param code 状态码
     * @desc 是否可以变更司机/车辆
     * @author zk
     * @date 2023/8/2
     **/
    public static boolean changeTruck(int code) {
        return code == CarWaybillEnum.PENDING_ORDER.getCode()
                || code == CarWaybillEnum.PENDING_VEHICLE.getCode();
    }

    /**
     * 运单状态
     * @return 状态集
     */
    public static List<Integer> initWaybillStatusV1() {
        List<Integer> statuses = new ArrayList<>();
        //statuses.add(CarWaybillEnum.PENDING_ORDER.getCode());
        statuses.add(CarWaybillEnum.PENDING_VEHICLE.getCode());
        statuses.add(CarWaybillEnum.EXIT_COMPLETED.getCode());
        return statuses;
    }

    /**
     * 运单状态
     * @return 状态集
     */
    public static List<Integer> initWaybillStatusV2() {
        List<Integer> statuses = new ArrayList<>();
        statuses.add(CarWaybillEnum.PENDING_ORDER.getCode());
        statuses.add(CarWaybillEnum.PENDING_VEHICLE.getCode());
        statuses.add(CarWaybillEnum.EXIT_COMPLETED.getCode());
        return statuses;
    }

    /**
     * 已结单总数
     * @return
     */
    public static List<Integer> accepted() {
        return Arrays.asList(CarWaybillEnum.PENDING_ORDER.getCode(),
                CarWaybillEnum.PENDING_VEHICLE.getCode(),
                CarWaybillEnum.EXIT_COMPLETED.getCode(),
                CarWaybillEnum.WAIT_LOADING.getCode(),
                CarWaybillEnum.COMPLETION_LOADING.getCode(),
                CarWaybillEnum.WAIT_UNLOADING.getCode(),
                CarWaybillEnum.COMPLETION_UNLOADING.getCode(),
                CarWaybillEnum.APPROVAL_TREAT.getCode(),
                CarWaybillEnum.APPROVAL_PASS.getCode(),
                CarWaybillEnum.APPROVAL_NO_PASS.getCode(),
                CarWaybillEnum.APPROVAL_IN.getCode()
        );
    }
}
