package com.bankaudit.rest.process.dao;

import java.util.List;

import org.hibernate.Session;
import org.jboss.logging.Logger;
import org.springframework.stereotype.Repository;

import com.bankaudit.dao.AbstractDao;
import com.bankaudit.process.model.RecommendationDetails;

@Repository("recommendationDetailsDao")
public class RecommendationDetailsDaoImpl extends AbstractDao implements RecommendationDetailsDao{
static final Logger logger = Logger.getLogger(AuditObservationDaoImpl.class);
	
	@Override
	public List<RecommendationDetails> getRecommendationDetails(Integer legalEntityCode, String auditId, String observationId, String recStatus){
		List<RecommendationDetails> recommendationDetailsLst = null;
		try {
			Session session =getSession();
	        session.setDefaultReadOnly(true);
	        logger.info("Inside getRecommendationDetails .."+ legalEntityCode +" auditId.. "+ auditId+" observationId.. "+observationId);
	        recommendationDetailsLst= session.createQuery(" from RecommendationDetails "
					+ " WHERE "
					+ " legalEntityCode =:legalEntityCode"
					+ " and auditId =:auditId "
					+ " and observationId =:observationId " )
					.setParameter("legalEntityCode", legalEntityCode)
					.setParameter("auditId", auditId)
					.setParameter("observationId", observationId)
					.list();
			
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}
		logger.info(" recommendationDetailsLst List.... "+ recommendationDetailsLst);
		return recommendationDetailsLst;
	}
	
	@Override
	public void deleteRecommendationDetailsById(Integer id) {
		
		try{
			Session session=getSession();
				session.createQuery("delete from RecommendationDetails where id =:id ")
				.setParameter("id", id).executeUpdate();
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}
	}
	
	@Override
	public void deleteRecommendationDetailsByObservationId(String observationId) {
		
		try{
			Session session=getSession();
				session.createQuery("delete from RecommendationDetails where observationId =:observationId ")
				.setParameter("observationId", observationId).executeUpdate();
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}
	}
}
