package com.ningdatech.carapi.common.constant;

import com.ningdatech.carapi.scheduler.enums.OperatorTypeEnum;
import io.swagger.annotations.ApiModel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.Objects;

/**
 * 车辆在线状态
 *
 * @author PoffyZhang
 */
@Getter
@AllArgsConstructor
@NoArgsConstructor
@ApiModel(value = "VehicleStatusEnum", description = "车辆在线状态-枚举")
public enum VehicleStatusEnum {
    /**
     * 在线
     */
    ONLINE(1, "在线", OperatorTypeEnum.ONLINE),

    /**
     *离线
     */
    OFFLINE(0, "离线",OperatorTypeEnum.OFFLINE),

    /**
     * 异常
     */
    EXCEPTIONAL(2, "异常",OperatorTypeEnum.EXCEPTION);


    private Integer code;
    private String desc;

    private OperatorTypeEnum operatorType;

    public String getDesc() {
        return desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public static String getDescByCode(Integer code) {
        if(Objects.isNull(code)){
            return StringUtils.EMPTY;
        }
        for (VehicleStatusEnum t : VehicleStatusEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.desc;
            }
        }
        return StringUtils.EMPTY;
    }

    public static OperatorTypeEnum getOperatorTypeByCode(Integer code) {
        if(Objects.isNull(code)){
            return null;
        }
        for (VehicleStatusEnum t : VehicleStatusEnum.values()) {
            if (code.equals(t.getCode())) {
                return t.operatorType;
            }
        }
        return null;
    }


    public boolean eq(String val) {
        return this.name().equals(val);
    }

}
