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

import com.bocloud.ims.entity.resource.hmc.HmcPartitionNetworkAdapter;
import com.bocloud.ims.repository.resource.common.EnhancedBaseRepository;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Deprecated
@Repository("hmcPartitionNetworkAdapterRepository")
public class HmcPartitionNetworkAdapterRepository extends EnhancedBaseRepository<HmcPartitionNetworkAdapter, Long> {

    /**
     * 查询逻辑分区下的所有虚拟以太网适配器
     *
     * @param partitionId 逻辑分区id
     */
    public List<HmcPartitionNetworkAdapter> getByPartitionId(long partitionId) {
        String sql = "select a.* from hmc_partition_network_adapter a where a.partition_id = :partitionId";
        Map<String, Object> params = new HashMap<>();
        params.put("partitionId", partitionId);
        return list(HmcPartitionNetworkAdapter.class, sql, params);
    }

    /**
     * 根据逻辑分区id和适配器id查询虚拟以太网适配器
     *
     * @param partitionId 逻辑分区id
     * @param adapterId 适配器id
     */
    public HmcPartitionNetworkAdapter getByPartitionIdAndAdapterId(long partitionId, long adapterId) {
        String sql = "select a.* from hmc_partition_network_adapter a " +
                "where a.partition_id = :partitionId and a.adapter_id = :adapterId";
        Map<String, Object> params = new HashMap<>();
        params.put("partitionId", partitionId);
        params.put("adapterId", adapterId);
        List<HmcPartitionNetworkAdapter> list = list(HmcPartitionNetworkAdapter.class, sql, params);
        return list == null || list.size() == 0 ? null : list.get(0);
    }

    public List<HmcPartitionNetworkAdapter> getByPartitionIdAndSwitchId(long partitionId, int switchId) {
        String sql = "select a.* from hmc_partition_network_adapter a " +
                "where a.partition_id = :partitionId and a.virtual_switch_id = :switchId";
        Map<String, Object> params = new HashMap<>();
        params.put("partitionId", partitionId);
        params.put("switchId", switchId);
        return list(HmcPartitionNetworkAdapter.class, sql, params);
    }
}
