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

import com.bocloud.common.utils.MapTools;
import com.bocloud.ims.entity.resource.hmc.HmcVolumeGroup;
import com.bocloud.ims.repository.resource.common.EnhancedBaseRepository;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author lkx007
 *
 */
@Deprecated
@Component("hmcVolumeGroup")
public class HmcVolumeGroupRepository extends EnhancedBaseRepository<HmcVolumeGroup, Long> {

    public List<HmcVolumeGroup> query(Long viosId, String groupName) {
        String sql = "select a.* from hmc_volume_group a where a.vios_id = :viosId ";
        if (groupName != null) {
            sql += " and a.group_name = :groupName ";
        }
        Map<String, Object> param = MapTools.simpleMap("viosId", viosId);
        if (groupName != null) {
            param.put("groupName", groupName);
        }
        List<Object> list = this.queryForList(sql, param, HmcVolumeGroup.class);
        List<HmcVolumeGroup> vgs = new ArrayList<>();
        for (Object obj : list) {
            vgs.add((HmcVolumeGroup) obj);
        }
        return vgs;
    }

    public HmcVolumeGroup query(Long id) {
        String sql = "SELECT a.* FROM hmc_volume_group a WHERE a.id = :id";
        Map<String, Object> param = MapTools.simpleMap("id", id);
        List<Object> list = this.queryForList(sql, param, HmcVolumeGroup.class);
        if (list.isEmpty()) {
            return null;
        }
        return (HmcVolumeGroup) list.get(0);
    }

    public boolean delete(Long viosId) {
        String sql = "delete from hmc_volume_group where vios_id = :viosId";
        Map<String, Object> param = MapTools.simpleMap("viosId", viosId);
        return this.update(sql, param) >= 0;
    }
}
