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

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