package gov.va.med.esr.common.persistent.hbp.hibernate;

import gov.va.med.esr.common.model.hbp.HealthBenefitPlanDefinition;
import gov.va.med.esr.common.model.hbp.HealthBenefitPlanDescription;
import gov.va.med.esr.common.model.hbp.HealthBenefitPlanName;
import gov.va.med.esr.common.persistent.hbp.HBPDefinitionDAO;
import gov.va.med.fw.model.EntityKey;
import gov.va.med.fw.persistent.DAOException;
import gov.va.med.fw.persistent.hibernate.GenericDAOImpl;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.commons.lang.Validate;
import org.springframework.dao.DataAccessException;

public class HBPDefinitionDAOImpl extends GenericDAOImpl implements HBPDefinitionDAO {

    /**
	 * 
	 */
	private static final long serialVersionUID = -6760824346883075161L;
	
	private static final String PARAM_PLANNAME_ID        = "Id";
    private static final String QRY_FIND_ALL_PLANNAMES = "healthBenefitPlanName_FindAll";
    private static final String QRY_PLANNAME_BY_ID = "healthBenefitPlanName_FindByID";

	@Override
	public HealthBenefitPlanName getHealthBenefitPlanNameById(
			EntityKey planNameId) throws DAOException {
		Validate.notNull(planNameId, "NULL planNameId not allowed.");
        try {
			List results = findByNamedQueryAndNamedParam(QRY_PLANNAME_BY_ID,
					PARAM_PLANNAME_ID, new BigDecimal(planNameId.getKeyValueAsString() ));

             return ((results == null) || results.isEmpty()) ? null : (HealthBenefitPlanName) results.get(0);
        } catch (DataAccessException e) {
            throw new DAOException("Failed find HealthBenefitPlanName by HealthBenefitPlanName.", e);
        }
		

	}

	@Override
	public List<HealthBenefitPlanName> findAllHealthBenefitPlanNames() throws DAOException {
	     
		List<HealthBenefitPlanName> planNames = null;
	        try {                       
	            planNames = (List<HealthBenefitPlanName>)find(QRY_FIND_ALL_PLANNAMES);
	        } catch (DataAccessException e) {
	            throw new DAOException("Failed to find all users.", e);
	        }
	        return planNames;
	}

}
