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.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 SangforVlanGroupRepositpry extends BasicGenericDao<SangforVlanGroup, Long> {
    public SangforVlanGroupRepositpry(JdbcTemplate jdbcTemplate, NamedParameterJdbcTemplate npJdbcTemplate) {
        super(jdbcTemplate, npJdbcTemplate);
    }

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

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

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

    public SangforVlanGroup query(Long id) {
        String sql = "select a.*  from sangfor_vlan_group a where a.is_deleted = 0 and a.id = :id ";
        Map<String, Object> params = MapTools.simpleMap("id", id);
        List<SangforVlanGroup> list = this.list(SangforVlanGroup.class, sql, params);
        if (list.isEmpty()) {
            return null;
        }
        return list.get(0);
    }
    public boolean removeByVid(Long vendorId, Long userId) {
        String sql = "update sangfor_vlan_group set is_deleted = 1, gmt_modify = :gmtModify, mender_id = :menderId where vendor_id = :vendorId";
        Map<String, Object> params = MapTools.simpleMap(Common.VENDORID, vendorId);
        params.put("gmtModify", new Date());
        params.put("menderId", userId);
        return this.execute(sql, params) > 0;
    }
    public Boolean remove(Long id, Long userId) {
        String sql = "update sangfor_vlan_group set is_deleted = 1, gmt_modify = :gmtModify, mender_id = :menderId where id = :id";
        Map<String, Object> params = MapTools.simpleMap(Common.ID, id);
        params.put("gmtModify", new Date());
        params.put("menderId", userId);
        return this.execute(sql, params) > 0;
    }

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