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

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

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Deprecated
@Repository("hmcPartitionScsiAdapterRepository")
public class HmcPartitionScsiAdapterRepository extends EnhancedBaseRepository<HmcPartitionScsiAdapter, Long> {

	public boolean deleteByPartitionId(Long partitionId) {
		String sql = "delete from hmc_partition_scsi_adapter where partition_id  = :partitionId";
		Map<String, Object> params = MapTools.simpleMap("partitionId", partitionId);
		return this.update(sql, params) >= 0;
	}

	public List<HmcPartitionScsiAdapter> queryByPartitionId(Long partitionId) {
		String sql = "select a.* from hmc_partition_scsi_adapter a where a.partition_id = :partitionId";
		Map<String, Object> param = MapTools.simpleMap("partitionId", partitionId);
		List<Object> list = this.queryForList(sql, param, HmcPartitionScsiAdapter.class);
		List<HmcPartitionScsiAdapter> adapters = new ArrayList<>();
		for (Object obj : list) {
			adapters.add((HmcPartitionScsiAdapter) obj);
		}
		return adapters;
	}

	public HmcPartitionScsiAdapter query(Long partitionId, Integer adapterId, String type) {
		String sql = "select a.* from hmc_partition_scsi_adapter a where "
				+ "a.partition_id = :partitionId and a.adapter_id = :adapterId  and a.type = :type";
		Map<String, Object> param = MapTools.simpleMap("partitionId", partitionId);
		param.put("adapterId", adapterId);
		param.put("type", type);
		List<HmcPartitionScsiAdapter> list = this.list(HmcPartitionScsiAdapter.class, sql, param);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}
}
