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.RiskControlDetails;

@Repository("riskControlDetailsDao")
public class RiskControlDetailsDaoImpl extends AbstractDao implements RiskControlDetailsDao{
	
	static final Logger logger = Logger.getLogger(AuditObservationDaoImpl.class);
	
	@Override
	public List<RiskControlDetails> getRiskControlDetails(Integer legalEntityCode, String auditId, String observationId, String recStatus){
		List<RiskControlDetails> riskControlDetailsLst = null;
		try {
			Session session =getSession();
	        session.setDefaultReadOnly(true);
	        logger.info("Inside getRiskControlDetails .."+ legalEntityCode +" auditId.. "+ auditId+" observationId.. "+observationId);
	        riskControlDetailsLst= session.createQuery(" from RiskControlDetails "
					+ " 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(" riskControlDetailsLst List.... "+ riskControlDetailsLst);
		return riskControlDetailsLst;
	}
	
	@Override
	public void deleteRiskControlDetailsById(Integer id) {
		
		try{
			Session session=getSession();
				session.createQuery("delete from RiskControlDetails where id =:id ")
				.setParameter("id", id).executeUpdate();
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}
	}
	
	@Override
	public void deleteRiskControlDetailsByObservationId(String observationId) {
		
		try{
			Session session=getSession();
				session.createQuery("delete from RiskControlDetails where observationId =:observationId ")
				.setParameter("observationId", observationId).executeUpdate();
		}catch(Exception e) {
			e.printStackTrace(System.out);
		}
	}
}
