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

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.commons.collections.CollectionUtils;

import com.uas.platform.b2b.model.SaleSend;
import com.uas.platform.b2b.model.SaleSendItem;
import com.uas.platform.b2b.support.SystemSession;

/**
 * 买家ERP的收料通知单
 */
public class AcceptNotify {

	private long an_venduu;
	private String an_currency;
	private Float an_rate;
	private String an_payment;
	private long an_buyeruu;
	private String an_remark;
	private List<AcceptNotifyDetail> details;

	public long getAn_venduu() {
		return an_venduu;
	}

	public void setAn_venduu(long an_venduu) {
		this.an_venduu = an_venduu;
	}

	public String getAn_currency() {
		return an_currency;
	}

	public void setAn_currency(String an_currency) {
		this.an_currency = an_currency;
	}

	public Float getAn_rate() {
		return an_rate;
	}

	public void setAn_rate(Float an_rate) {
		this.an_rate = an_rate;
	}

	public String getAn_payment() {
		return an_payment;
	}

	public void setAn_payment(String an_payment) {
		this.an_payment = an_payment;
	}

	public long getAn_buyeruu() {
		return an_buyeruu;
	}

	public void setAn_buyeruu(long an_buyeruu) {
		this.an_buyeruu = an_buyeruu;
	}

	public String getAn_remark() {
		return an_remark;
	}

	public void setAn_remark(String an_remark) {
		this.an_remark = an_remark;
	}

	public List<AcceptNotifyDetail> getDetails() {
		return details;
	}

	public void setDetails(List<AcceptNotifyDetail> details) {
		this.details = details;
	}

	public AcceptNotify() {

	}

	/**
	 * 卖家做的发货单，转为买家的收料通知
	 * 
	 * @param send
	 */
	public AcceptNotify(SaleSend send) {
		this.an_buyeruu = send.getCustUserUU();
		this.an_currency = send.getCurrency();
		this.an_payment = send.getPayments();
		this.an_rate = send.getRate();
		this.an_remark = send.getRemark();
		this.an_venduu = send.getEnUU();
		this.details = new ArrayList<AcceptNotifyDetail>();
		if (!CollectionUtils.isEmpty(send.getSendItems())) {
			for (SaleSendItem item : send.getSendItems()) {
				this.details.add(new AcceptNotifyDetail(item));
			}
		}
	}

	/**
	 * 买家主动做的收料通知，转到平台的发货单
	 * 
	 * @return
	 */
	public SaleSend convert() {
		SaleSend send = new SaleSend();
		send.setEnUU(this.getAn_venduu());
		send.setCustUU(SystemSession.getUser().getEnterprise().getUu());
		send.setCurrency(this.an_currency);
		send.setRate(this.an_rate);
		send.setPayments(this.an_payment);
		send.setCustUserUU(this.an_buyeruu);
		send.setRemark(this.an_remark);
		Set<SaleSendItem> items = new HashSet<SaleSendItem>();
		if (!CollectionUtils.isEmpty(details)) {
			for (AcceptNotifyDetail detail : details)
				items.add(detail.convert());
		}
		send.setSendItems(items);
		return send;
	}

}
