package kz.cafe.client.rest;

import java.util.*;
import javax.servlet.http.*;
import javax.ws.rs.*;
import javax.ws.rs.core.*;
import kz.cafe.client.*;
import kz.cafe.client.rest.wrappers.*;
import kz.cafe.constants.*;
import kz.cafe.db.*;
import kz.cafe.db.model.*;

@Path("/system")
public class FESystem extends FEAbstractService{
   //private static Log log = LogFactory.getLog(FEAdmin.class);

   private static final String LOG = "[ADMIN] ";





   public FESystem(@Context HttpServletRequest hsr){
      super(ServiceRequestModel.buildUpponServlet(hsr), LOG);
   }





   
   @SuppressWarnings("unchecked")
   @GET
   @Path("/messages/{LANG}")
   @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
   public JRDescriptorListResponse getI18N(@PathParam("LANG") String sLang){
      JRDescriptorListResponse response = new JRDescriptorListResponse();

      try{
         InterfaceConstants.LANGS lang = validateLang(sLang);

         for(MAbstractDescriptor mAbstractDescriptor :
                            (List<MAbstractDescriptor>) MongoService.getListFrontEnd(MI18NClient.class, 0)){

            if(response.checkDeleted(mAbstractDescriptor)){
               JRDescriptorListResponse.JMItem item = response.add();
               item.fillIn(lang, mAbstractDescriptor);
            }
         }
      }
      catch (Throwable e){
         response = new JRDescriptorListResponse(e);
      }
      
      super.responseTime(response);
      return response;
   }
   
}
