package com.bocloud.nms.model.hillstone;

import java.util.Objects;

public class SNMPHostModel extends HillStoneGenericModel {
    private Long vendorId; // 所属平台
    private String hostname; // 主机
    private Integer hostType; // 1->trap主机；2->snmp主机
    private Integer hostnameType; // ??? 默认2
    private Integer mode; // 1->IP/掩码；2->IP范围；3->IP地址
    private Long netSegIpv4; // 网络设置IPV4
    private Long netSegIpmaskIpv4; // 网络设置IPV4/掩码
    private Long rangeStartIpv4; // IPV4起始
    private Long rangeEndIpv4; // IPV4终止
    private String netSegIpv6; // 网络设置IPV6
    private Long netSegIpmaskLenIpv6; // 网络设置IPV6/掩码
    private String rangeStartIpv6; // IPV6起始
    private String rangeEndIpv6; // IPV6终止
    private Integer version; // 3->v3; 0->v1; 1->v2c
    private Integer access; // 权限 1->只读； 2->可写
    private String community; // 团体字
    private Integer port;

    public Long getVendorId() {
        return vendorId;
    }

    public void setVendorId(Long vendorId) {
        this.vendorId = vendorId;
    }

    public String getHostname() {
        return hostname;
    }

    public void setHostname(String hostname) {
        this.hostname = hostname;
    }

    public Integer getHostType() {
        return hostType;
    }

    public void setHostType(Integer hostType) {
        this.hostType = hostType;
    }

    public Integer getHostnameType() {
        return hostnameType;
    }

    public void setHostnameType(Integer hostnameType) {
        this.hostnameType = hostnameType;
    }

    public Integer getMode() {
        return mode;
    }

    public void setMode(Integer mode) {
        this.mode = mode;
    }

    public Long getNetSegIpv4() {
        return netSegIpv4;
    }

    public void setNetSegIpv4(Long netSegIpv4) {
        this.netSegIpv4 = netSegIpv4;
    }

    public Long getNetSegIpmaskIpv4() {
        return netSegIpmaskIpv4;
    }

    public void setNetSegIpmaskIpv4(Long netSegIpmaskIpv4) {
        this.netSegIpmaskIpv4 = netSegIpmaskIpv4;
    }

    public Long getRangeStartIpv4() {
        return rangeStartIpv4;
    }

    public void setRangeStartIpv4(Long rangeStartIpv4) {
        this.rangeStartIpv4 = rangeStartIpv4;
    }

    public Long getRangeEndIpv4() {
        return rangeEndIpv4;
    }

    public void setRangeEndIpv4(Long rangeEndIpv4) {
        this.rangeEndIpv4 = rangeEndIpv4;
    }

    public String getNetSegIpv6() {
        return netSegIpv6;
    }

    public void setNetSegIpv6(String netSegIpv6) {
        this.netSegIpv6 = netSegIpv6;
    }

    public Long getNetSegIpmaskLenIpv6() {
        return netSegIpmaskLenIpv6;
    }

    public void setNetSegIpmaskLenIpv6(Long netSegIpmaskLenIpv6) {
        this.netSegIpmaskLenIpv6 = netSegIpmaskLenIpv6;
    }

    public String getRangeStartIpv6() {
        return rangeStartIpv6;
    }

    public void setRangeStartIpv6(String rangeStartIpv6) {
        this.rangeStartIpv6 = rangeStartIpv6;
    }

    public String getRangeEndIpv6() {
        return rangeEndIpv6;
    }

    public void setRangeEndIpv6(String rangeEndIpv6) {
        this.rangeEndIpv6 = rangeEndIpv6;
    }

    public Integer getVersion() {
        return version;
    }

    public void setVersion(Integer version) {
        this.version = version;
    }

    public Integer getAccess() {
        return access;
    }

    public void setAccess(Integer access) {
        this.access = access;
    }

    public String getCommunity() {
        return community;
    }

    public void setCommunity(String community) {
        this.community = community;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    public String getName() {
        // 1->IP/掩码；2->IP范围；3->IP地址
        if (mode != null && mode == 1) {
            if (netSegIpv4 != null && netSegIpmaskIpv4 != null) {
                return Ipv4.convertIp(netSegIpv4) + "/" + netSegIpmaskIpv4;
            }
            if (netSegIpv6 != null && netSegIpmaskLenIpv6 != null) {
                return netSegIpv6 + "/" + netSegIpmaskLenIpv6;
            }
        } else if (mode != null && mode == 2) {
            if (rangeStartIpv4 != null && rangeEndIpv4 != null) {
                return Ipv4.convertIp(rangeStartIpv4) + "-" + Ipv4.convertIp(rangeEndIpv4);
            }
            if (rangeStartIpv6 != null && rangeEndIpv6 != null) {
                return rangeStartIpv6 + "-" + rangeEndIpv6;
            }
        } else if (mode != null && mode == 3) {
            return hostname;
        }
        return hostname;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        SNMPHostModel snmpHost = (SNMPHostModel) o;
        return Objects.equals(vendorId, snmpHost.vendorId) &&
            Objects.equals(hostname, snmpHost.hostname) &&
            Objects.equals(mode, snmpHost.mode) &&
            Objects.equals(netSegIpv4, snmpHost.netSegIpv4) &&
            Objects.equals(netSegIpmaskIpv4, snmpHost.netSegIpmaskIpv4) &&
            Objects.equals(rangeStartIpv4, snmpHost.rangeStartIpv4) &&
            Objects.equals(rangeEndIpv4, snmpHost.rangeEndIpv4) &&
            Objects.equals(netSegIpv6, snmpHost.netSegIpv6) &&
            Objects.equals(netSegIpmaskLenIpv6, snmpHost.netSegIpmaskLenIpv6) &&
            Objects.equals(rangeStartIpv6, snmpHost.rangeStartIpv6) &&
            Objects.equals(rangeEndIpv6, snmpHost.rangeEndIpv6);
    }

    @Override
    public int hashCode() {
        return Objects.hash(vendorId, hostname, mode, netSegIpv4, netSegIpmaskIpv4, rangeStartIpv4, rangeEndIpv4, netSegIpv6, netSegIpmaskLenIpv6, rangeStartIpv6, rangeEndIpv6);
    }
}
