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

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

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

	public Boolean deleteByHeaId(Long heaId) {
		String sql = "delete from hmc_hea_physical_port where hea_id = :heaId";
		Map<String, Object> params = MapTools.simpleMap("heaId", heaId);
		return this.update(sql, params) > 0;
	}

	public List<HmcHeaPhysicalPort> queryByHeaId(Long heaId) {
		String sql = "select a.* from hmc_hea_physical_port a where a.hea_id = :heaId";
		Map<String, Object> param = MapTools.simpleMap("heaId", heaId);
		List<Object> list = this.queryForList(sql, param, HmcHeaPhysicalPort.class);
		List<HmcHeaPhysicalPort> ports = new ArrayList<>();
		for (Object obj : list) {
			ports.add((HmcHeaPhysicalPort) obj);
		}
		return ports;
	}
}
