package com.contabilidad.FacadeConta;

import com.contabilidad.EntConta.Catalogo;
import com.contabilidad.EntConta.CatalogoCuentas;

import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;
import java.util.ArrayList;
import java.util.List;

@Stateless
public class CuentasFacade extends AbstractFacade<Catalogo> implements CuentasFacadeLocal {

    @PersistenceContext(unitName = "contabilidad")
    private EntityManager em;

    @Override
    public EntityManager getEntityManager() {
        return em;
    }


    @Override
    public List<Catalogo> obtenerCuentasPrincipales() {
        Query q = em.createNativeQuery("select * from catalogo where nivel = 1", Catalogo.class);
        List<Catalogo> rs = new ArrayList<>();

        rs.addAll(q.getResultList());

        return rs;
    }

    @Override
    public List<Catalogo> obtenerSiguienteNivel(String codigCun) {

        Query q = em.createNativeQuery("select * from catalogo where general = ?", Catalogo.class);
        q.setParameter(1, codigCun);

        List<Catalogo> rs = new ArrayList<>();
        rs.addAll(q.getResultList());

        return rs;
    }


    public CuentasFacade() {
        super(Catalogo.class);
    }
}
