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

import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.intf.impl.JdbcGenericDao;
import com.bocloud.ims.entity.resource.hmc.HmcVirtualNetworkBridge;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Component;

import java.util.Date;
import java.util.List;
import java.util.Map;

@Deprecated
@Component("hmcVirtualNetworkBridgeRepository")
public class HmcVirtualNetworkBridgeRepository extends JdbcGenericDao<HmcVirtualNetworkBridge, Long> {

    public HmcVirtualNetworkBridgeRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate) {
        super(jdbcTemplate, npJdbcTemplate);
    }

    public List<HmcVirtualNetworkBridge> listByServerId(Long serverId) {
        String sql = "select a.* from hmc_virtual_network_bridge a where a.is_deleted = 0 and a.server_id = :serverId";
        Map<String, Object> params = MapTools.simpleMap("serverId", serverId);
        return this.list(HmcVirtualNetworkBridge.class, sql, params);
    }

    public boolean remove(Long id, Long userId) {
        String sql = "update hmc_virtual_network_bridge set is_deleted = true , gmt_modify = :gmtModify ,mender_id = :menderId where is_deleted = 0 and id = :id";
        Map<String, Object> params = MapTools.simpleMap("id", id);
        params.put("menderId", userId);
        params.put("gmtModify", new Date());
        return this.execute(sql, params) > 0;
    }

}
