package com.mvc.iot;

/**
 * IOT平台统一的任务状态
 */
public enum IotTaskStatus {
    CREATE_FAIL("-1", "创建失败"),
    WAITING("0", "未下发"),
    SENT("1", "已发送"),
    DELIVERED("2", "已送达"),
    CANCELED("3", "取消"),
    EXPIRED("4", "过期"),
    TIMEOUT("5", "超时"),
    UNKNOWN("6", "未知"),
    FAILED("7", "失败"),
    SUCCESSFUL("9", "成功");

    private String code;
    private String name;

    public String getCode() {
        return code;
    }

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

    /**
     * 通过OneNet返回的code获取任务状态
     *
     * @param code
     * @return
     */
    public static IotTaskStatus getByOneNetResultCode(String code) {
        switch (code) {
            case "1":
                return WAITING;
            case "2":
                return CANCELED;
            case "3":
                return SENT;
            case "4":
                return EXPIRED;
            case "5":
                return SUCCESSFUL;
            case "6":
                return FAILED;
            case "7":
                return TIMEOUT;
            case "8":
                return UNKNOWN;
            default:
                return null;
        }
    }

    /**
     * 通过Aep返回的code获取任务状态
     *
     * @param code
     * @return
     */
    public static IotTaskStatus getByAepResultCode(String code) {
        switch (code) {
            case "0":
                return SUCCESSFUL;
            case "1":
                return SENT;
            case "2":
                return DELIVERED;
            case "3":
                return FAILED;
            default:
                return null;
        }
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
