/*
 * 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.ws.user;

import com.arrebol.apc.controller.mobile.controller.user.UserController;
import com.arrebol.apc.model.core.User;
import java.io.Serializable;
import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.GenericEntity;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

/**
 *
 * @author Carlos Janitzio Zavala Lopez <janitzio.zavala@arrebol.com.mx>
 */
@Path("users")
public class UserWS implements Serializable {

    @GET
    @Path("list-by-office")
    @Produces(MediaType.APPLICATION_JSON)
    public Response listOfUsersByOffice(@QueryParam("office") String office) {
        logger.debug("listOfUsersByOffice");
        Response response;
        try {
            UserController controller = new UserController();
            GenericEntity<List<User>> results
                    = new GenericEntity<List<User>>(
                            controller.listOfUsersByOffice(office)
                    ) {
            };

            response = Response.ok(results).build();
        } catch (Exception e) {
            logger.error("listOfUsersByOffice", e);
            response = Response.status(Response.Status.NOT_ACCEPTABLE).build();
        }
        return response;
    }

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

}
