package com.aimluck.eip.modules.screens;

import java.util.ArrayList;
import java.util.Date;

import net.sf.json.JSONArray;

import org.apache.turbine.util.RunData;
import org.apache.velocity.context.Context;

import com.aimluck.eip.common.ALEipConstants;

public class BookJSONScreen extends ALJSONScreen {

  public boolean validate(RunData rundata, ArrayList msgList) {
    Date start_date = rundata.getParameters().getDate("view_month");
    Date end_date = rundata.getParameters().getDate("view_month2");
    if (start_date != null && end_date != null && start_date.after(end_date)) {
      msgList.add("開始日は終了日より前の日付に設定して下さい。");
    }
    return (msgList.size() == 0);
  }
  
  @Override
  protected String getJSONString(RunData rundata, Context context)
      throws Exception {
    String result = new JSONArray().toString();
    ArrayList msgList = new ArrayList();

    if (!validate(rundata, msgList)) {
      //this.setResultData(this);
      msgList.add("test");
      this.addErrorMessages(msgList);
      this.putData(rundata, context);

      ArrayList list = (ArrayList) context
          .get(ALEipConstants.ERROR_MESSAGE_LIST);
      JSONArray json = JSONArray.fromObject(list);
      result = json.toString();

    }
    return result;
  }

}
