/*
 * Arrebol Consultancy copyright.
 * 
 * This code belongs to Arrebol Consultancy
 * its use, redistribution or modification are prohibited 
 * without written authorization from Arrebol Consultancy.
 */
package com.arrebol.apc.controller.mobile.repository.admin;

import com.arrebol.apc.controller.mobile.repository.GenericRepository;
import com.arrebol.apc.model.ModelParameter;
import com.arrebol.apc.model.admin.constance.StableSmallBoxCfg;
import java.io.Serializable;
import java.util.List;
import javax.persistence.Tuple;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
public class StableSmallBoxRepository extends GenericRepository implements Serializable {

    /**
     *
     * @param xmlQuery
     * @param parameters
     * @return
     * @throws Exception
     */
    public String findIdEntity(String xmlQuery, List<ModelParameter> parameters) throws Exception {
        try {
            for (Tuple tuple : xmlQueryTuple(xmlQuery, parameters)) {
                return tuple.get(StableSmallBoxCfg.FIELD_ID, String.class);
            }

            return null;
        } catch (Exception e) {
            logger.error("findIdEntity", e);
            throw e;
        }
    }

    /**
     *
     * @param hbmQuery
     * @param parameters
     * @return
     * @throws Exception
     */
    public boolean updateStableSmallBox(String hbmQuery, List<ModelParameter> parameters) throws Exception {
        try {
            return xmlUpdateOrDelete(hbmQuery, parameters);
        } catch (Exception e) {
            logger.error("updateStableSmallBox", e);
            throw e;
        }
    }

    /**
     *
     * @param hbmQuery
     * @param parameters
     * @return
     * @throws Exception
     */
    public Long countStableSmallBoxByOfficeEqualsToCurrentDate(String hbmQuery, List<ModelParameter> parameters) throws Exception {
        try {
            return (Long) genericObjectFromEntity(Long.class, hbmQuery, parameters);
        } catch (Exception e) {
            logger.error("countStableSmallBoxByOfficeEqualsToCurrentDate", e);
            throw e;
        }
    }

    final Logger logger = LogManager.getLogger(getClass());
}
