package com.bocloud.ims.entity.resource.hmc;

import com.bocloud.entity.annotations.Column;
import com.bocloud.entity.annotations.Table;

import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

@Table("hmd_server_virtual_switch")
public class HmdServerVirtualSwitch extends HmdGenericEntity {
    @Column("server_id")
    private Long serverId; // 所属服务器id，对应hmd_server表的id字段
    @Column("name")
    private String name; // 名称
    @Column("uuid")
    private String uuid; // 唯一标识
    @Column("status")
    private String status; // 状态
    @Column("switch_id")
    private Integer switchId; // 交换机id

    private HmdServer server; // 所属服务器
    private List<HmdServerVirtualNetwork> virtualNetworks; // 连接的虚拟网络

    public Long getServerId() {
        return serverId;
    }

    public void setServerId(Long serverId) {
        this.serverId = serverId;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Integer getSwitchId() {
        return switchId;
    }

    public void setSwitchId(Integer switchId) {
        this.switchId = switchId;
    }

    public List<HmdServerVirtualNetwork> getVirtualNetworks() {
        return virtualNetworks;
    }

    public void setVirtualNetworks(List<HmdServerVirtualNetwork> virtualNetworks) {
        this.virtualNetworks = virtualNetworks;
    }

    public void setVirtualNetworkUrls(List<String> urls) {
        this.virtualNetworks = urls.stream().map(url -> {
            HmdServerVirtualNetwork network = new HmdServerVirtualNetwork();
            network.setUrl(url);
            return network;
        }).collect(Collectors.toList());
    }

    public HmdServer getServer() {
        return server;
    }

    public void setServer(HmdServer server) {
        this.server = server;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        HmdServerVirtualSwitch that = (HmdServerVirtualSwitch) o;
        return Objects.equals(uuid, that.uuid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(uuid);
    }
}

