package com.fp.armas.portal.dao.registro;

import java.util.List;

import javax.persistence.Query;

import com.fp.armas.portal.dao.general.GenericDaoImpl;
import com.fp.armas.portal.model.Tcustpeople;
import com.fp.armas.portal.model.Tcustpersonaddress;
import com.fp.armas.portal.model.Tsafeuserdetail;
import com.fp.armas.portal.util.FechaUtil;
import com.fp.armas.portal.util.RegistroException;

/**
 * Objeto de acceso a datos de la tabla {@link Tsafeuserdetail}
 * @author dcruz
 *
 */
public class UsuarioDetalleDao extends GenericDaoImpl<Tsafeuserdetail> {

	public UsuarioDetalleDao() {
		super(Tsafeuserdetail.class);
	}

	/**
	 * Busca y retorna todos los usuarios encontrados
	 * @param personcode
	 * @return
	 * @throws RegistroException
	 */
	@SuppressWarnings("unchecked")
	public List<Tsafeuserdetail> buscaUserDetail(Long personcode) throws RegistroException{		
		Query query = this.getEntityManager().createQuery("SELECT o FROM Tsafeuserdetail o WHERE o.id.personcode=:personcode AND  o.id.dateto=:dateto");
		query.setParameter("personcode", (long)personcode);
		query.setParameter("dateto", FechaUtil.obtenerFecha(2999, 11, 31));
		List<Tsafeuserdetail> listpeople = query.getResultList();
		if(listpeople != null && !listpeople.isEmpty()){
			return listpeople;
		}
		return null;
	}
	
	
}
