package com.ruoyi.rocketmq.snmp.dto;

import lombok.Data;
import org.snmp4j.mp.SnmpConstants;
import org.snmp4j.security.SecurityLevel;

import java.util.*;

/**
 * 交换机OID配置DTO (支持SNMP v2c和v3)
 */
@Data
public class SwitchOidDto {
    private String ip;
    private String community;
    private int port = 161;
    private int version = SnmpConstants.version2c; // 默认v2c
    private int timeout = 5000;
    private int retries = 2;

    // SNMP v3特有参数
    private String securityName;
    private String authProtocol;
    private String authPassword;
    private String privProtocol;
    private String privPassword;
    private int securityLevel = SecurityLevel.AUTH_PRIV;

    // OID配置
    private Map<String, String> netOID = new LinkedHashMap<>();
    private Map<String, String> otherOID = new LinkedHashMap<>();
    private Map<String, String> entityOID = new LinkedHashMap<>();
    private Map<String, String> pwrOID = new LinkedHashMap<>();
    private Map<String, String> fanOID = new LinkedHashMap<>();
    private Map<String, String> mpuOID = new LinkedHashMap<>();
    private Map<String, String> moduleOID = new LinkedHashMap<>();
    private Map<String, String> powerOID = new LinkedHashMap<>();

    // 过滤条件
    private Map<String, List<String>> filters = new HashMap<>();

    public SwitchOidDto() {
    }

    public SwitchOidDto(String ip, String community) {
        this.ip = ip;
        this.community = community;
    }

    public SwitchOidDto(String ip, String community, int port) {
        this.ip = ip;
        this.community = community;
        this.port = port;
    }

    /**
     * 获取支持的所有设备类型
     */
    public List<String> getSupportedDeviceTypes() {
        List<String> types = new ArrayList<>();
        if (!netOID.isEmpty()) types.add("net");
        if (!otherOID.isEmpty()) types.add("other");
        if (!entityOID.isEmpty()) types.add("entity");
        if (!pwrOID.isEmpty()) types.add("pwr");
        if (!fanOID.isEmpty()) types.add("fan");
        if (!mpuOID.isEmpty()) types.add("mpu");
        if (!moduleOID.isEmpty()) types.add("module");
        if (!powerOID.isEmpty()) types.add("power");
        return types;
    }

    /**
     * 根据设备类型获取OID映射
     */
    public Map<String, String> getOidsByType(String deviceType) {
        switch (deviceType) {
            case "net":
                return netOID;
            case "other":
                return otherOID;
            case "entity":
                return entityOID;
            case "pwr":
                return pwrOID;
            case "fan":
                return fanOID;
            case "mpu":
                return mpuOID;
            case "module":
                return moduleOID;
            case "power":
                return powerOID;
            default:
                return Collections.emptyMap();
        }
    }

    /**
     * 根据设备类型获取过滤条件
     */
    public List<String> getFilterByType(String deviceType) {
        return filters.get(deviceType);
    }

    /**
     * 判断是否为SNMP v3
     */
    public boolean isV3() {
        return version == SnmpConstants.version3;
    }
}