package org.nl.acs.device_driver.basedriver.agv.utils;

import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;
import org.nl.common.exception.BadRequestException;
import org.nl.config.MapOf;

import java.util.Map;

@AllArgsConstructor
@Getter
public enum AgvActionEnum {
    //agv动作类型
    ACTION_STATUS(MapOf.of("待机", "0","请求取货", "1", "取货完成", "2", "请求放货", "3", "放货完成", "4", "请求开门", "5", "请求关门", "6", "请求充电", "7")),
    //agv状态类型
    DEVICE_STATUS(MapOf.of("待机", "0","关机", "1", "运行中", "2", "交通管制", "3", "任务等待", "4", "充电中", "5", "故障中", "6", "低电量", "7"));

    private Map<String, String> code;

    public String code(String desc) {
        String code = this.getCode().get(desc);
        if (StringUtils.isNotEmpty(code)) {
            return code;
        }
        throw new BadRequestException(this.name() + "对应类型" + desc + "未定义");
    }

    public Long longCode(String desc) {
        String code = this.getCode().get(desc);
        if (StringUtils.isNotEmpty(code)) {
            return Long.valueOf(code);
        }
        throw new BadRequestException(this.name() + "对应类型" + desc + "未定义");
    }

    public String check(String code) {
        for (Map.Entry<String, String> entry : this.getCode().entrySet()) {
            if (entry.getValue().equals(code)) {
                return entry.getKey();
            }
        }
        throw new BadRequestException(this.name() + "对应类型" + code + "未定义");
    }
}
