package com.uas.platform.b2b.openapi.model;

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

import org.springframework.util.CollectionUtils;

public class TEMP_FORECAST extends Data {

	private String date;

	private Double qty;

	private String needDate;

	private String endDate;

//	private String trader;

	public Double getQty() {
		return qty;
	}

	public void setQty(Double qty) {
		this.qty = qty;
	}

//	public String getTrader() {
//		return trader;
//	}
//
//	public void setTrader(String trader) {
//		this.trader = trader;
//	}

	public String getDate() {
		return date;
	}

	public void setDate(String date) {
		this.date = date;
	}

	public String getNeedDate() {
		return needDate;
	}

	public void setNeedDate(String needDate) {
		this.needDate = needDate;
	}

	public String getEndDate() {
		return endDate;
	}

	public void setEndDate(String endDate) {
		this.endDate = endDate;
	}

	public static List<Forecast> reduce(List<TEMP_FORECAST> temps) {
		List<Forecast> forecasts = new ArrayList<Forecast>();
		if (!CollectionUtils.isEmpty(temps)) {
			Map<TEMP_DATA, List<ForecastItem>> map = new HashMap<TEMP_DATA, List<ForecastItem>>();
			for (TEMP_FORECAST temp : temps) {
				TEMP_DATA data = new TEMP_DATA(temp.getBrand(), temp.getOrg_item(), temp.getItem_desc(), temp.getItem_spec(),
						temp.getItem_unit());
				List<ForecastItem> items = null;
				if (map.containsKey(data)) {
					items = map.get(data);
				} else {
					items = new ArrayList<ForecastItem>();
				}
				items.add(new ForecastItem(temp.getDate(), temp.getQty(), temp.getNeedDate(), temp.getEndDate()));
				map.put(data, items);
			}
			for (TEMP_DATA temp : map.keySet()) {
				forecasts
						.add(new Forecast(temp.getBrand(), temp.getCode(), temp.getTitle(), temp.getSpec(), temp.getUnit(), map.get(temp)));
			}
		}
		return forecasts;
	}

}
