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

import com.bocloud.common.utils.MapTools;
import com.bocloud.ims.entity.resource.hmc.HmcProfileScsiAdapter;
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("HmcProfileScsiAdapterRepository")
public class HmcProfileScsiAdapterRepository extends EnhancedBaseRepository<HmcProfileScsiAdapter, Long> {

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

	public boolean deleteByProfileId(Long profileId) {
		String sql = "delete from hmc_profile_scsi_adapter where profile_id = :profileId";
		Map<String, Object> params = MapTools.simpleMap("profileId", profileId);
		return this.update(sql, params) > 0;
	}

	public List<HmcProfileScsiAdapter> queryByProfileId(Long profileId) {
		String sql = "select a.* from hmc_profile_scsi_adapter a where a.profile_id = :profileId";
		Map<String, Object> param = MapTools.simpleMap("profileId", profileId);
		List<Object> list = this.queryForList(sql, param, HmcProfileScsiAdapter.class);
		List<HmcProfileScsiAdapter> adapters = new ArrayList<>();
		for (Object obj : list) {
			adapters.add((HmcProfileScsiAdapter) obj);
		}
		return adapters;
	}

	public HmcProfileScsiAdapter queryByProfileIdAndAdapterId(Long profileId, int adapterId) {
		String sql = "select a.* from hmc_profile_scsi_adapter a where a.profile_id = :profileId and a.adapter_id = :adapterId";
		Map<String, Object> param = MapTools.simpleMap("profileId", profileId);
		param.put("adapterId", adapterId);
		List<Object> list = this.queryForList(sql, param, HmcProfileScsiAdapter.class);
		return list == null || list.size() == 0 ? null : (HmcProfileScsiAdapter) list.get(0);
	}
}
