package com.bizzan.bitrade.test.service;

import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.Test;
import org.springframework.ui.freemarker.FreeMarkerTemplateUtils;

import com.bizzan.bitrade.util.DateUtil;

import freemarker.core.ParseException;
import freemarker.template.Configuration;
import freemarker.template.MalformedTemplateNameException;
import freemarker.template.Template;
import freemarker.template.TemplateException;
import freemarker.template.TemplateNotFoundException;

public class EmailTest {

	@Test
	public void testBlast() throws TemplateNotFoundException, MalformedTemplateNameException, ParseException, IOException, TemplateException {
		try {
			Map<String, Object> model = new HashMap<>();
	    	String dateTime = DateUtil.getDateTime();
			model.put("time", dateTime);
			model.put("timewos", dateTime.substring(0,dateTime.length()-3));
			model.put("email", "xxxx");
			model.put("contractName", "xx");
			List detailList = new ArrayList();
			Map<String, Object> detail = new HashMap<>();
			detail.put("volume", 100);
			detail.put("leverage", "100x");
			detail.put("direction", "看涨");
			detailList.add(detail);
			model.put("detail", detailList);
			
			Configuration cfg = new Configuration(Configuration.VERSION_2_3_26);
	        cfg.setClassForTemplateLoading(this.getClass(), "/templates");
	        Template template = cfg.getTemplate("blast.ftl");
	        String html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
	        System.out.println(html);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	@Test
	public void testRecharge() {
		try {
			Map<String, Object> model = new HashMap<>();
	    	String dateTime = DateUtil.getDateTime();
			model.put("time", dateTime);
			model.put("timewos", dateTime.substring(0,dateTime.length()-3));
			model.put("email", "xxxx");
			model.put("amount", 10);
			model.put("unit", "ETH");
			
			Configuration cfg = new Configuration(Configuration.VERSION_2_3_26);
	        cfg.setClassForTemplateLoading(this.getClass(), "/templates");
	        Template template = cfg.getTemplate("recharge.ftl");
	        String html = FreeMarkerTemplateUtils.processTemplateIntoString(template, model);
	        System.out.println(html);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}
