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.PurchaseInquiryMouldDetail;
import com.uas.platform.b2b.model.PurchaseInquiryMouldItem;

/**
 * 买家ERP系统的模具询价明细
 * 
 *
 */
public class InquiryMouldDet {

	private Long b2b_imi_id;
	private Long idd_id;
	private String idd_code;
	private Short idd_detno;
	private String idd_pscode;
	private String idd_psname;
	private String idd_pstype;
	private String idd_remark;
	private Double idd_price;

	private List<InquiryMouldDetail> details;

	public Long getB2b_imi_id() {
		return b2b_imi_id;
	}

	public void setB2b_imi_id(Long b2b_imi_id) {
		this.b2b_imi_id = b2b_imi_id;
	}

	public Long getIdd_id() {
		return idd_id;
	}

	public void setIdd_id(Long idd_id) {
		this.idd_id = idd_id;
	}

	public String getIdd_code() {
		return idd_code;
	}

	public void setIdd_code(String idd_code) {
		this.idd_code = idd_code;
	}

	public Short getIdd_detno() {
		return idd_detno;
	}

	public void setIdd_detno(Short idd_detno) {
		this.idd_detno = idd_detno;
	}

	public String getIdd_pscode() {
		return idd_pscode;
	}

	public void setIdd_pscode(String idd_pscode) {
		this.idd_pscode = idd_pscode;
	}

	public String getIdd_psname() {
		return idd_psname;
	}

	public void setIdd_psname(String idd_psname) {
		this.idd_psname = idd_psname;
	}

	public String getIdd_pstype() {
		return idd_pstype;
	}

	public void setIdd_pstype(String idd_pstype) {
		this.idd_pstype = idd_pstype;
	}

	public String getIdd_remark() {
		return idd_remark;
	}

	public void setIdd_remark(String idd_remark) {
		this.idd_remark = idd_remark;
	}

	public Double getIdd_price() {
		return idd_price;
	}

	public void setIdd_price(Double idd_price) {
		this.idd_price = idd_price;
	}

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

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

	/**
	 * 转为平台的模具明细
	 * 
	 * @return
	 */
	public PurchaseInquiryMouldItem convert() {
		PurchaseInquiryMouldItem purchaseInquiryMouldItem = new PurchaseInquiryMouldItem();
		purchaseInquiryMouldItem.setCode(this.idd_code);
		purchaseInquiryMouldItem.setDetno(this.idd_detno);
		purchaseInquiryMouldItem.setErpSourceId(this.idd_id);
		purchaseInquiryMouldItem.setPrice(this.idd_price);
		purchaseInquiryMouldItem.setPsCode(this.idd_pscode);
		purchaseInquiryMouldItem.setPsName(this.idd_psname);
		purchaseInquiryMouldItem.setPsType(this.idd_pstype);
		purchaseInquiryMouldItem.setRemark(this.idd_remark);
		if (!CollectionUtils.isEmpty(this.details)) {
			Set<PurchaseInquiryMouldDetail> inquiryMouldDetails = new HashSet<PurchaseInquiryMouldDetail>();
			for (InquiryMouldDetail detail : details) {
				inquiryMouldDetails.add(detail.convert());
			}
			purchaseInquiryMouldItem.setInquiryMouldDetails(inquiryMouldDetails);
		}

		return purchaseInquiryMouldItem;
	}

	public InquiryMouldDet() {

	}

	public InquiryMouldDet(PurchaseInquiryMouldItem item) {
		this.b2b_imi_id = item.getId();
		this.idd_code = item.getCode();
		this.idd_detno = item.getDetno();
		this.idd_price = item.getReply();
		this.idd_pscode = item.getPsCode();
		this.idd_psname = item.getPsName();
		this.idd_pstype = item.getPsType();
		this.idd_remark = item.getRemark();
		this.idd_id = item.getErpSourceId();
		if (!CollectionUtils.isEmpty(item.getInquiryMouldDetails())) {
			details = new ArrayList<InquiryMouldDetail>();
			for (PurchaseInquiryMouldDetail detail : item.getInquiryMouldDetails()) {
				details.add(new InquiryMouldDetail(detail));
			}
		}
	}

}
