package com.palmnest.model;

import java.io.Serializable;
import java.util.List;

import com.palmnest.model.notice.WxtemplateConfigPara;
import com.palmnest.model.notice.WxtemplateMessageConfigModel;


/**
 * 模板消息
 *
 * @author wangxz
 * @date 2017年12月2日
 */
public class TemplateMessage implements Serializable {

	private static final long serialVersionUID = 1529275678423566597L;

	//接收者openid
	private String                     openId;
	//模板ID
	private String                     templateId;
	//模板跳转链接
	private String                     url;
	// 消息顶部的颜色  
	private String                     topColor;
	// 参数列表  
	private List<WxtemplateConfigPara> templateParamList;

	public String getOpenId() {
		return openId;
	}

	public void setOpenId(String openId) {
		this.openId = openId;
	}

	public String getTemplateId() {
		return templateId;
	}

	public void setTemplateId(String templateId) {
		this.templateId = templateId;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getTopColor() {
		return topColor;
	}

	public void setTopColor(String topColor) {
		this.topColor = topColor;
	}


	public List<WxtemplateConfigPara> getTemplateParamList() {
		return templateParamList;
	}

	public void setTemplateParamList(List<WxtemplateConfigPara> templateParamList) {
		this.templateParamList = templateParamList;
	}

	public String toJSON() {
		StringBuffer buffer = new StringBuffer();
		buffer.append("{");
		buffer.append(String.format("\"touser\":\"%s\"", this.openId)).append(",");
		buffer.append(String.format("\"template_id\":\"%s\"", this.templateId)).append(",");
		buffer.append(String.format("\"url\":\"%s\"", this.url)).append(",");
		buffer.append(String.format("\"topcolor\":\"%s\"", this.topColor)).append(",");
		buffer.append("\"data\":{");
		WxtemplateConfigPara param = null;
		for (int i = 0; i < this.templateParamList.size(); i++) {
			param = templateParamList.get(i);
			// 判断是否追加逗号
			if (i < this.templateParamList.size() - 1) {

				buffer.append(String.format("\"%s\": {\"value\":\"%s\",\"color\":\"%s\"},", param.getParam_key(), param.getValue(), "#173177"));
			} else {
				buffer.append(String.format("\"%s\": {\"value\":\"%s\",\"color\":\"%s\"}", param.getParam_key(), param.getValue(), "#173177"));
			}
		}
		buffer.append("}");
		buffer.append("}");
		return buffer.toString();
	}

}