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

import com.bocloud.database.core.intf.impl.JdbcGenericDao;
import com.bocloud.ims.entity.resource.hmc.HmcPartitionMemory;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

@Deprecated
@Repository
public class HmcPartitionMemoryRepository extends JdbcGenericDao<HmcPartitionMemory, Long> {

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

    public HmcPartitionMemory getByPartitionId(Long partitionId) {
        String sql = "select * from hmc_partition_memory where partition_id = :partitionId and is_deleted = 0  ";
        Map<String, Object> params = new HashMap<>();
        params.put("partitionId", partitionId);
        List<HmcPartitionMemory> list = super.list(HmcPartitionMemory.class, sql, params);
        return Optional.ofNullable(list).map(o -> o.stream().findFirst().orElse(null)).orElse(null);
    }
}
