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.Tcustcompany;
import com.fp.armas.portal.model.Tcustpeople;
import com.fp.armas.portal.model.Tcustpersonaddress;
import com.fp.armas.portal.util.FechaUtil;
import com.fp.armas.portal.util.PortalMessages;
import com.fp.armas.portal.util.RegistroException;

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

	public PersonaNaturalDao() {
		super(Tcustpeople.class);
	}
	
	/**
	 * Busca y retorna todas las personas naturales vigentes encontradas
	 * @param personcode
	 * @return
	 * @throws RegistroException
	 */
	@SuppressWarnings("unchecked")
	public List<Tcustpeople> buscaPersonaNatural(Long personcode) throws RegistroException{		
		Query query = this.getEntityManager().createQuery("SELECT o FROM Tcustpeople 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<Tcustpeople> listpeople = query.getResultList();
		if(listpeople != null && !listpeople.isEmpty()){
			return listpeople;
		}
		return null;
	}

}
