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

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

	public List<HmcHostEthernetAdapter> listByServerId(Long serverId) {
		String sql = "select a.* from hmc_host_ethernet_adapter a where a.server_id = :serverId";
		Map<String, Object> param = MapTools.simpleMap("serverId", serverId);
		List<Object> list = this.queryForList(sql, param, HmcHostEthernetAdapter.class);
		List<HmcHostEthernetAdapter> heas = new ArrayList<>();
		for (Object obj : list) {
			heas.add((HmcHostEthernetAdapter) obj);
		}
		return heas;
	}

	public HmcHostEthernetAdapter getById(Long id) {
		String sql = "select a.* from hmc_host_ethernet_adapter a where a.id = :id";
		Map<String, Object> param = MapTools.simpleMap("id", id);
		List<HmcHostEthernetAdapter> list = this.list(HmcHostEthernetAdapter.class, sql, param);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}

	public Boolean deleteByServerId(Long serverId) {
		String sql = "delete from hmc_host_ethernet_adapter where server_id = :serverId";
		Map<String, Object> params = MapTools.simpleMap("serverId", serverId);
		return this.update(sql, params) > 0;
	}

	public HmcHostEthernetAdapter getByAdapterId(Long serverId, Long adapterId) {
		String sql = "select a.* from hmc_host_ethernet_adapter a where a.server_id = :serverId and a.adapter_id = :adapterId";
		Map<String, Object> param = MapTools.simpleMap("serverId", serverId);
		param.put("adapterId", adapterId);
		List<HmcHostEthernetAdapter> list = this.list(HmcHostEthernetAdapter.class, sql, param);
		if (list.isEmpty()) {
			return null;
		}
		return list.get(0);
	}
}
