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

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



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






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