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

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

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

@Table("hmd_server_shared_processor_pool")
public class HmdServerSharedProcessorPool extends HmdGenericEntity {
    @Column("server_id")
    private Long serverId; // 所属服务器id，对应hmd_server表的id字段
    @Column("name")
    private String name; // 共享存储池的名称
    @Column("uuid")
    private String uuid; // 共享存储池uuid
    @Column("pool_id")
    private Integer poolId; // 共享处理器池id
    @Column("current_reserved_processing_units")
    private Double currentReservedProcessingUnits; // 当前保留的处理单元数
    @Column("pending_reserved_processing_units")
    private Double pendingReservedProcessingUnits; // 下一个保留的处理单元数
    @Column("available_processor_units")
    private Double availableProcessorUnits; // 可用的处理单元数
    @Column("maximum_processor_units")
    private Double maximumProcessorUnits; // 最大处理单元数

    private HmdServer server; // 所属服务器

    private List<HmdPartition> assignedPartitions = new ArrayList<>();

    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 Integer getPoolId() {
        return poolId;
    }

    public void setPoolId(Integer poolId) {
        this.poolId = poolId;
    }

    public Double getCurrentReservedProcessingUnits() {
        return currentReservedProcessingUnits;
    }

    public void setCurrentReservedProcessingUnits(Double currentReservedProcessingUnits) {
        this.currentReservedProcessingUnits = currentReservedProcessingUnits;
    }

    public Double getPendingReservedProcessingUnits() {
        return pendingReservedProcessingUnits;
    }

    public void setPendingReservedProcessingUnits(Double pendingReservedProcessingUnits) {
        this.pendingReservedProcessingUnits = pendingReservedProcessingUnits;
    }

    public Double getAvailableProcessorUnits() {
        return availableProcessorUnits;
    }

    public void setAvailableProcessorUnits(Double availableProcessorUnits) {
        this.availableProcessorUnits = availableProcessorUnits;
    }

    public Double getMaximumProcessorUnits() {
        return maximumProcessorUnits;
    }

    public void setMaximumProcessorUnits(Double maximumProcessorUnits) {
        this.maximumProcessorUnits = maximumProcessorUnits;
    }

    public List<HmdPartition> getAssignedPartitions() {
        return assignedPartitions;
    }

    public void setAssignedPartitions(List<HmdPartition> assignedPartitions) {
        this.assignedPartitions = assignedPartitions;
    }

    public void setAssignedPartitionUrls(List<String> urls) {
        this.assignedPartitions = urls.stream().map(url -> {
            HmdPartition partition = new HmdPartition();
            partition.setUrl(url);
            return partition;
        }).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;
        }
        HmdServerSharedProcessorPool that = (HmdServerSharedProcessorPool) o;
        return Objects.equals(uuid, that.uuid);
    }

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

