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

import com.uas.platform.b2b.model.*;
import com.uas.platform.b2b.support.SystemSession;
import org.apache.commons.collections.CollectionUtils;

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

/**
 * 买家ERP系统的打样申请单
 * 
 * @author yingp
 * 
 */
public class ProductSample {

	private Long ps_id;
	private String ps_code;
	private String ps_recordor;
	private Date ps_indate;
	private Long ps_appmanuu;
	private String ps_prodcode;

	/**
	 * 是否收费
	 */
	private String ps_isfree;
	private Date ps_delivery;
	private String ps_envrequire;
	private String ps_scope;
	private String ps_remark;

	/**
	 * 附件
	 */
	private String ps_attach;

	/**
	 * 附件
	 */
	private List<Attach> attaches;
	private List<ProductSampleDetail> details;

	/**
	 * b2bID
	 */
	private Long ps_b2bid;

	public Long getPs_id() {
		return ps_id;
	}

	public void setPs_id(Long ps_id) {
		this.ps_id = ps_id;
	}

	public String getPs_code() {
		return ps_code;
	}

	public void setPs_code(String ps_code) {
		this.ps_code = ps_code;
	}

	public String getPs_recordor() {
		return ps_recordor;
	}

	public void setPs_recordor(String ps_recordor) {
		this.ps_recordor = ps_recordor;
	}

	public Date getPs_indate() {
		return ps_indate;
	}

	public void setPs_indate(Date ps_indate) {
		this.ps_indate = ps_indate;
	}

	public Long getPs_appmanuu() {
		return ps_appmanuu;
	}

	public void setPs_appmanuu(Long ps_appmanuu) {
		this.ps_appmanuu = ps_appmanuu;
	}

	public String getPs_prodcode() {
		return ps_prodcode;
	}

	public void setPs_prodcode(String ps_prodcode) {
		this.ps_prodcode = ps_prodcode;
	}

	public String getPs_isfree() {
		return ps_isfree;
	}

	public void setPs_isfree(String ps_isfree) {
		this.ps_isfree = ps_isfree;
	}

	public Date getPs_delivery() {
		return ps_delivery;
	}

	public void setPs_delivery(Date ps_delivery) {
		this.ps_delivery = ps_delivery;
	}

	public String getPs_envrequire() {
		return ps_envrequire;
	}

	public void setPs_envrequire(String ps_envrequire) {
		this.ps_envrequire = ps_envrequire;
	}

	public String getPs_scope() {
		return ps_scope;
	}

	public void setPs_scope(String ps_scope) {
		this.ps_scope = ps_scope;
	}

	public String getPs_remark() {
		return ps_remark;
	}

	public void setPs_remark(String ps_remark) {
		this.ps_remark = ps_remark;
	}

	public String getPs_attach() {
		return ps_attach;
	}

	public void setPs_attach(String ps_attach) {
		this.ps_attach = ps_attach;
	}

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

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

    public Long getPs_b2bid() {
        return ps_b2bid;
    }

    public void setPs_b2bid(Long ps_b2bid) {
        this.ps_b2bid = ps_b2bid;
    }

    /**
	 * @return
	 */
	public PurchaseProofing convert() {
		PurchaseProofing proofing = new PurchaseProofing();
		proofing.setErpId(ps_id);
		proofing.setCode(ps_code);
		proofing.setDate(ps_indate);
		proofing.setDelivery(ps_delivery);
		proofing.setEnUU(SystemSession.getUser().getEnterprise().getUu());
		proofing.setEnterprise(new EnterpriseInfo(SystemSession.getUser().getEnterprise()));
		proofing.setEnvrequiry(ps_envrequire);
		proofing.setIsCharge(ps_isfree);
		Product product = new Product();
		product.setCode(ps_prodcode);
		proofing.setProduct(product);
		proofing.setRecorder(ps_recordor);
		proofing.setRemark(ps_remark);
		proofing.setScope(ps_scope);
		UserBaseInfo user = new UserBaseInfo();
		user.setUserUU(ps_appmanuu);
		proofing.setUser(user);
		proofing.setUserUU(ps_appmanuu);
		if (!CollectionUtils.isEmpty(this.details)) {
			Set<PurchaseProofingItem> proofingItems = new HashSet<PurchaseProofingItem>();
			for (ProductSampleDetail detail : details) {
				proofingItems.add(detail.convert());
			}
			proofing.setProofingItems(proofingItems);
		}
		if(!CollectionUtils.isEmpty(this.attaches)) {
			Set<com.uas.platform.b2b.model.Attach> b2bAttaches = new HashSet<com.uas.platform.b2b.model.Attach>();
			for(Attach attach : this.attaches) {
				com.uas.platform.b2b.model.Attach b2bAttach = attach.convertToB2bAttach("买家上传打样申请附件");
				b2bAttaches.add(b2bAttach);
			}
			proofing.setAttachs(b2bAttaches);
		}
		return proofing;
	}

	public void setAttaches(List<Attach> attaches) {
		this.attaches = attaches;
	}

	public List<Attach> getAttaches() {
		return attaches;
	}
}
