package jp.agentec.abook.abv.bl.acms.client.parameters;

import java.net.URLEncoder;

import jp.agentec.abook.abv.bl.common.exception.ABVRuntimeException;
import jp.agentec.adf.util.StringUtil;

/**
 * GET checkapi/shopSyncWatermark/?sid=&screen=&lastFetchDate=(任意)
 */
public class ShopSyncWatermarkParameters extends AcmsParameters {

	public static final String SCREEN_OPERATION_LIST = "OPERATION_LIST";
	public static final String SCREEN_REPORT_LIST = "REPORT_LIST";

	private final String screen;
	private final String lastFetchDate;

	public ShopSyncWatermarkParameters(String sid, String screen, String lastFetchDate) {
		super(sid);
		this.screen = screen;
		this.lastFetchDate = lastFetchDate;
	}

	@Override
	public String toHttpParameterString(String encoding) {
		try {
			StringBuilder sb = new StringBuilder();
			sb.append(URLEncoder.encode("sid", encoding)).append("=")
					.append(URLEncoder.encode(getSid(), encoding).replace("+", "%20"));
			sb.append("&");
			sb.append(URLEncoder.encode("screen", encoding)).append("=")
					.append(URLEncoder.encode(screen, encoding).replace("+", "%20"));
			if (!StringUtil.isNullOrEmpty(lastFetchDate)) {
				sb.append("&");
				sb.append(URLEncoder.encode("lastFetchDate", encoding)).append("=")
						.append(URLEncoder.encode(lastFetchDate, encoding).replace("+", "%20"));
			}
			return sb.toString();
		} catch (Exception e) {
			throw new ABVRuntimeException(e);
		}
	}
}
