package com.bocloud.ims.repository.resource;

import com.bocloud.common.utils.Common;
import com.bocloud.common.utils.MapTools;
import com.bocloud.database.core.intf.impl.BasicGenericDao;
import com.bocloud.ims.entity.resource.SangforBridgeInfo;
import com.bocloud.ims.entity.resource.SangforVlanGroup;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

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

@Repository
public class SangforBridgeInfoRepository extends BasicGenericDao<SangforBridgeInfo, Long> {
    public SangforBridgeInfoRepository(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate) {
        super(jdbcTemplate, npJdbcTemplate);
    }

    public List<SangforBridgeInfo> listByVid(Long vendorId) {
        String sql =
                "select a.*  from sangfor_bridge_info a where a.is_deleted = 0 and a.vendor_id = :vendorId ";
        Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
        return this.list(SangforBridgeInfo.class, sql, params);
    }

    public List<SangforBridgeInfo> listByNetworkId(Long networkId) {
        String sql = "select a.*  from sangfor_bridge_info a where a.is_deleted = 0 and a.network_id = :networkId ";
        Map<String, Object> params = MapTools.simpleMap("networkId", networkId);
        return this.list(SangforBridgeInfo.class, sql, params);
    }

    public List<SangforBridgeInfo> listByNetworkUuid(String networkId) {
        String sql = "select a.*  from sangfor_bridge_info a where a.is_deleted = 0 and a.network_uuid = :networkId ";
        Map<String, Object> params = MapTools.simpleMap("networkId", networkId);
        return this.list(SangforBridgeInfo.class, sql, params);
    }

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

    public boolean remove(Long id, Long userId) {
        String sql = "update sangfor_bridge_info set is_deleted = 1,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;
    }
}
