/*
 * 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.controller.bitacora;

import com.arrebol.apc.controller.mobile.repository.bitacora.BitacoraRepository;
import com.arrebol.apc.model.core.Office;
import com.arrebol.apc.model.system.logs.Bitacora;
import java.io.Serializable;
import java.util.Date;
import java.util.UUID;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

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

    /**
     *
     * @param action
     * @param userName
     * @param comments
     * @param createdBy
     * @param office
     * @param description
     * @return
     */
    public boolean insertBitacoraRecord(String action, String userName, String comments, String createdBy, String office, String description) {
        boolean success;
        try {
            BitacoraRepository repository = new BitacoraRepository();
            Bitacora bitacora = new Bitacora();

            bitacora.setId(UUID.randomUUID().toString());
            bitacora.setNameUser(userName);
            bitacora.setAction(action);
            bitacora.setCommentsUser(comments);
            bitacora.setCreatedBy(createdBy);
            bitacora.setCreatedOn(new Date());
            bitacora.setOffice(new Office(office));
            bitacora.setDescription(description);

            success = repository.saveBitacora(bitacora);
        } catch (Exception e) {
            success = false;
            logger.error("insertBitacoraRecord", e);
        }
        return success;
    }

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