package com.ruoyi.bst.device.domain.enums;

import java.util.List;

import com.ruoyi.common.utils.collection.CollectionUtils;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public enum DeviceStatus {
    STORAGE("0", "仓库中"),
    AVAILABLE("1", "待骑行"),
    RESERVED("2", "预约中"),
    IN_USE("3", "骑行中"),
    TEMP_LOCKED("4", "临时锁车"),
    DISPATCHING("6", "调度中"),
    DISABLED("8", "禁用"),
    Q_LOCKED("9", "强制锁车");

    private final String code;
    private final String name;

    public static String getNameByCode(String code) {
        for (DeviceStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status.getName();
            }
        }
        return "未知状态";
    }

    // 允许入仓的设备状态
    public static List<String> canIn() {
        return CollectionUtils.map(DeviceStatus::getCode, AVAILABLE, DISPATCHING, DISABLED);
    }

    // 允许出仓的设备状态
    public static List<String> canOut() {
        return CollectionUtils.map(DeviceStatus::getCode, STORAGE);
    }

    // 允许禁用的设备状态
    public static List<String> canDisable() {
        return CollectionUtils.map(DeviceStatus::getCode, AVAILABLE, DISPATCHING, STORAGE);
    }

    // 允许启用的设备状态
    public static List<String> canEnable() {
        return CollectionUtils.map(DeviceStatus::getCode, DISABLED);
    }

    // 允许管理员开锁的设备状态
    public static List<String> canAdminUnlock() {
        return CollectionUtils.map(DeviceStatus::getCode, DISPATCHING, STORAGE, AVAILABLE, TEMP_LOCKED, Q_LOCKED,
                IN_USE);
    }

    // 允许用户开锁的设备状态
    public static List<String> canUserUnlock() {
        return CollectionUtils.map(DeviceStatus::getCode, IN_USE, AVAILABLE, TEMP_LOCKED);
    }

    // 允许用户锁车的设备状态
    public static List<String> canUserLock() {
        return CollectionUtils.map(DeviceStatus::getCode, AVAILABLE, TEMP_LOCKED, DISPATCHING, IN_USE);
    }

    // 允许管理员锁车的状态
    public static List<String> canAdminLock() {
        return CollectionUtils.map(DeviceStatus::getCode, AVAILABLE, TEMP_LOCKED, DISPATCHING, IN_USE, Q_LOCKED);
    }

    // 允许用户使用的设备状态
    public static List<String> canUse() {
        return CollectionUtils.map(DeviceStatus::getCode, AVAILABLE);
    }

    // 允许返回运营区上电
    public static List<String> canBackUnlock() {
        return CollectionUtils.map(DeviceStatus::getCode, Q_LOCKED);
    }

    // 允许强制锁车的状态
    public static List<String> canQLock() {
        return CollectionUtils.map(DeviceStatus::getCode, IN_USE, Q_LOCKED);
    }

    // 不允许处理定位BUG的设备状态
    public static List<String> notHandleLocationBug() {
        return CollectionUtils.map(DeviceStatus::getCode, STORAGE, DISABLED);
    }
}
