package com.jsowell.pile.vo.web;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.jsowell.common.util.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class BillingTemplateVO {
	// 计费模板id
	private String templateId;

	// 计费模板编号
	private String templateCode;

	// 计费模板名称
	private String templateName;

	// 计费模板备注
	private String remark;

	// 发布时间
	private String publishTime;

	// 设备类型 1-电动汽车桩；2-电动自行车桩
	private String deviceType;

	// 尖时段电费
	private BigDecimal sharpElectricityPrice;
	// 尖时段服务费
	private BigDecimal sharpServicePrice;
	// 尖时段时间 逗号分割的时段段
	private String sharpApplyDate;

	// 峰时段电费
	private BigDecimal peakElectricityPrice;
	// 峰时段电费
	private BigDecimal peakServicePrice;
	// 峰时段时间 逗号分割的时段段
	private String peakApplyDate;

	// 平时段电费
	private BigDecimal flatElectricityPrice;
	// 平时段服务费
	private BigDecimal flatServicePrice;
	// 平时段时间 逗号分割的时段段
	private String flatApplyDate;

	// 谷时段电费
	private BigDecimal valleyElectricityPrice;
	// 谷时段服务费
	private BigDecimal valleyServicePrice;
	// 平时段时间 逗号分割的时段段
	private String valleyApplyDate;

	@Override
	public String toString() {
		return new ToStringBuilder(this, ToStringStyle.JSON_STYLE)
				.append("templateId", templateId)
				.append("templateCode", templateCode)
				.append("templateName", templateName)
				.append("publishTime", publishTime)
				.append("remark", remark)
				.append("deviceType", deviceType)
				.append("sharpElectricityPrice", sharpElectricityPrice)
				.append("sharpServicePrice", sharpServicePrice)
				.append("sharpApplyDate", sharpApplyDate)
				.append("peakElectricityPrice", peakElectricityPrice)
				.append("peakServicePrice", peakServicePrice)
				.append("peakApplyDate", peakApplyDate)
				.append("flatElectricityPrice", flatElectricityPrice)
				.append("flatServicePrice", flatServicePrice)
				.append("flatApplyDate", flatApplyDate)
				.append("valleyElectricityPrice", valleyElectricityPrice)
				.append("valleyServicePrice", valleyServicePrice)
				.append("valleyApplyDate", valleyApplyDate)
				.toString();
	}

	public Map<Integer, List<String>> getTimeMap() {
		Map<Integer, List<String>> resultMap = Maps.newHashMap();
		if (StringUtils.isNotBlank(this.getSharpApplyDate())) {
			resultMap.put(0x00, Lists.newArrayList(this.getSharpApplyDate().split(",")));
		}
		if (StringUtils.isNotBlank(this.getPeakApplyDate())) {
			resultMap.put(0x01, Lists.newArrayList(this.getPeakApplyDate().split(",")));
		}
		if (StringUtils.isNotBlank(this.getFlatApplyDate())) {
			resultMap.put(0x02, Lists.newArrayList(this.getFlatApplyDate().split(",")));
		}
		if (StringUtils.isNotBlank(this.getValleyApplyDate())) {
			resultMap.put(0x03, Lists.newArrayList(this.getValleyApplyDate().split(",")));
		}
		return resultMap;
	}

	public List<BillingDetailVO> getBillingDetailList() {
		List<BillingDetailVO> resultList = Lists.newArrayList();
		if (StringUtils.isNotBlank(this.getSharpApplyDate())) {
			List<String> list = Lists.newArrayList(this.getSharpApplyDate().split(","));
			resultList.add(BillingDetailVO.builder()
					.timeType("1")
					.applyTime(list)
					.electricityPrice(this.sharpElectricityPrice)
					.servicePrice(this.sharpServicePrice)
					.build());
		}
		if (StringUtils.isNotBlank(this.getPeakApplyDate())) {
			List<String> list = Lists.newArrayList(this.getPeakApplyDate().split(","));
			resultList.add(BillingDetailVO.builder()
					.timeType("2")
					.applyTime(list)
					.electricityPrice(this.peakElectricityPrice)
					.servicePrice(this.peakServicePrice)
					.build());
		}
		if (StringUtils.isNotBlank(this.getFlatApplyDate())) {
			List<String> list = Lists.newArrayList(this.getFlatApplyDate().split(","));
			resultList.add(BillingDetailVO.builder()
					.timeType("3")
					.applyTime(list)
					.electricityPrice(this.flatElectricityPrice)
					.servicePrice(this.flatServicePrice)
					.build());
		}
		if (StringUtils.isNotBlank(this.getValleyApplyDate())) {
			List<String> list = Lists.newArrayList(this.getValleyApplyDate().split(","));
			resultList.add(BillingDetailVO.builder()
					.timeType("4")
					.applyTime(list)
					.electricityPrice(this.valleyElectricityPrice)
					.servicePrice(this.valleyServicePrice)
					.build());
		}
		return resultList;
	}

}
