
package jp.co.sint.beans.front;

import java.util.Collection;

import java.sql.Connection;

import javax.servlet.http.HttpServletRequest;

import jp.co.sint.config.SIConfig;
import jp.co.sint.tools.SIURLParameter;
import jp.co.sint.tools.SIUtil;

public class UICmdtyList extends UICmdtyRanking {
  
  int index = 0;
  int mode = 1;
  int limit = 20;
  
  public int getIndex() {
    return index;
  }
  
  public int getMode() {
    return mode;
  }
  
  public int getLimit() {
    return limit;
  }
  
  public void setIndex(int index) {
    this.index = index;
  }
  
  public void setMode(int mode) {
    this.mode = mode;
  }
  
  public void setLimit(int limit) {
    this.limit = limit;
  }
  
  public UICmdtyList(){}
  
  public UICmdtyList(int mode,int index,int limit){
    this.setMode(mode);
    this.setIndex(index);
    this.setLimit(limit);
  }
  
  public void init(SIURLParameter urlParam) {
    if(SIUtil.isNotNull((String)urlParam.getParam("inx"))) {
      this.setIndex(Integer.parseInt((String)urlParam.getParam("inx")));
    }
    if(SIUtil.isNotNull((String)urlParam.getParam("mode"))) {
      this.setMode(Integer.parseInt((String)urlParam.getParam("mode")));
    }
    if(SIUtil.isNotNull((String)urlParam.getParam("limit"))) {
      this.setLimit(Integer.parseInt((String)urlParam.getParam("limit")));
    }
  }
  
  public Collection getItemCollection(Connection lConnection,HttpServletRequest request) {
    return getItemCollection(lConnection,request,index,mode,limit);
  }
  
  public Collection getRecommendCollection(Connection lConnection,HttpServletRequest request) {
    return getCollection(lConnection,request,index,SIConfig.RECOMMEND_LIST_ITEMS);
  }
  
  public String getLastUpdate(Connection lConnection) {
    return getLastUpdate(lConnection,index);
  }
  
  public String getCtgryGroupName(){
    String res= "";
    for (int i=0;i<SIConfig.reccomendGroup.length;i++) {
      if (SIConfig.reccomendGroup[i][0].equals(String.valueOf(this.index))){
        res=SIConfig.reccomendGroup[i][1];
        break;
      }
    }
    return res;
  }
}