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

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

//   private UserSession4 session = null;





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






   
   //---------------------------------------------------------------------------------------------
   //Sales
   //---------------------------------------------------------------------------------------------
   @GET
   @Path("/list/{LANG}/{TIME}")
   @Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
   @SuppressWarnings({ "unchecked" })
   public JRNewsListResponse getSales(@PathParam("LANG") String sLang,
                                      @PathParam("TIME") long lTime){
      JRNewsListResponse response = new JRNewsListResponse();
      
      try{
         InterfaceConstants.LANGS lang = validateLang(sLang);
         
         for(MNews mNews : (List<MNews>) MongoService.getListFrontEnd(MNews.class, lTime)){
            if(response.checkDeleted(mNews)){
               JRNewsListResponse.JMItem item = response.add();
               item.fillIn(lang, mNews);
               
               item.CID = mNews.CID;
               
               item.date_notification = mNews.date_notification;
               item.main_screen = mNews.showMainScreen;
               item.news_screen = mNews.showNews;
            }
         }
      }
      catch(Throwable e){
         response = new JRNewsListResponse(e);
      }
      
      updateStatistic(MAbstractStatistics.F_NEWS);
      super.responseTime(response);
      return response;
   }
}