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("/city")
public class FECity extends FEAbstractService{
//   private static Log log = LogFactory.getLog(FESale.class);

   private static final String LOG = "[JR SALE] ";



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






   
   //---------------------------------------------------------------------------------------------
   //Cities
   //---------------------------------------------------------------------------------------------
   @GET
   @Path("/list/{LANG}/{TIME}")
   @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
   @SuppressWarnings({ "unchecked" })
   public JRCityListResponse getCities(@PathParam("LANG") String sLang,
                                       @PathParam("TIME") long lTime){
      JRCityListResponse response = new JRCityListResponse();
      
      try{
         InterfaceConstants.LANGS lang = validateLang(sLang);
         
         for(MCity mCity : (List<MCity>) MongoService.getListFrontEnd(MCity.class, lTime)){
            if(response.checkDeleted(mCity)){
               JRCityListResponse.JMItem item = response.add();
               item.fillIn(lang, mCity);
               
               item.GMT     = mCity.GMT;
               item.hasCafe = mCity.hasCafe;
           }
         }
      }
      catch(Throwable e){
         response = new JRCityListResponse(e);
      }
      
      super.responseTime(response);
      return response;
   }
}