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

import com.bocloud.common.utils.MapTools;
import com.bocloud.ims.entity.resource.hmc.HmcProfileLhea;
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("hmcProfileLheaRepository")
public class HmcProfileLheaRepository extends EnhancedBaseRepository<HmcProfileLhea, Long> {
    public boolean deleteByPartitionId(Long partitionId) {
        String sql = "delete from hmc_profile_lhea where profile_id in (select id from hmc_profile where partition_id = :partitionId)";
        Map<String, Object> params = MapTools.simpleMap("partitionId", partitionId);
        return this.update(sql, params) > 0;
    }

    public boolean deleteByProfileId(Long profileId) {
        String sql = "delete from hmc_profile_lhea where profile_id = :profileId";
        Map<String, Object> params = MapTools.simpleMap("profileId", profileId);
        return this.update(sql, params) > 0;
    }

    public List<HmcProfileLhea> queryByProfileId(Long profileId) {
        String sql = "select a.* from hmc_profile_lhea a where a.profile_id = :profileId";
        Map<String, Object> param = MapTools.simpleMap("profileId", profileId);
        List<Object> list = this.queryForList(sql, param, HmcProfileLhea.class);
        List<HmcProfileLhea> lheas = new ArrayList<>();
        for (Object obj : list) {
            lheas.add((HmcProfileLhea) obj);
        }
        return lheas;
    }
}
