package com.uas.search.console.b2b.model;

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

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

/**
 * 平台里面，以供应商的角度来查看采购订单变更单 <br>
 * 级联变更明细
 * 
 * @author yingp
 * 
 */
@Table(name = PurchaseChangesSimpleInfo.TABLE_NAME)
@Entity
public class PurchaseChangesSimpleInfo {

	/**
	 * 表名
	 */
	public static final String TABLE_NAME = "PURC$CHANGES";

	/**
	 * 各字段列名（也是存储索引时的field名）
	 */
	public static final String ID_FIELD = "pc_id";

	public static final String CODE_FIELD = "pc_code";

	public static final String ENTERPRISE_FIELD = "pc_enuu";

	public static final String DATE_FIELD = "pc_indate";

	public static final String STATUS_FIELD = "pc_status";

	public static final String VEND_FIELD = "pc_venduu";

	public static final String ITEMS_FIELD = "pcd_pcid";

	public static final String ORDERCODE_FIELD = "pc_pucode";

	public static final String UNNEEDREPLY_FIELD = "pc_unneedreply";

	@Id
	@Column(name = ID_FIELD)
	private Long id;

	/**
	 * 日期
	 */
	@Column(name = DATE_FIELD)
	private Date date;

	/**
	 * 企业UU
	 */
	@OneToOne
	@JoinColumn(name = ENTERPRISE_FIELD, insertable = false, updatable = false)
	private EnterpriseSimpleInfo enterprise;

	/**
	 * 采购变更单供应商UU
	 */
	@OneToOne
	@JoinColumn(name = VEND_FIELD, insertable = false, updatable = false)
	private EnterpriseSimpleInfo vend;

	/**
	 * 采购变更单号
	 */
	@Column(name = CODE_FIELD)
	private String code;

	/**
	 * 状态（未回复、已回复）
	 */
	@Column(name = STATUS_FIELD)
	private Short status;

	/**
	 * 采购订单编号
	 */
	@Column(name = ORDERCODE_FIELD)
	private String orderCode;

	/**
	 * 采购变更单明细
	 */
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinColumn(name = ITEMS_FIELD, insertable = false, updatable = false)
	private Set<PurchaseOrderChangeItemSimpleInfo> orderChangeItems;

	/**
	 * 不需要供应商确认(1,0)
	 */
	@Column(name = UNNEEDREPLY_FIELD)
	private Short unNeedReply;

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public EnterpriseSimpleInfo getVend() {
		return vend;
	}

	public void setVend(EnterpriseSimpleInfo vend) {
		this.vend = vend;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public Short getStatus() {
		return status;
	}

	public void setStatus(Short status) {
		this.status = status;
	}

	public String getOrderCode() {
		return orderCode;
	}

	public void setOrderCode(String orderCode) {
		this.orderCode = orderCode;
	}

	public Date getDate() {
		return date;
	}

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

	public EnterpriseSimpleInfo getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(EnterpriseSimpleInfo enterprise) {
		this.enterprise = enterprise;
	}

	public Set<PurchaseOrderChangeItemSimpleInfo> getOrderChangeItems() {
		return orderChangeItems;
	}

	public void setOrderChangeItems(Set<PurchaseOrderChangeItemSimpleInfo> orderChangeItems) {
		this.orderChangeItems = orderChangeItems;
	}

	public Short getUnNeedReply() {
		return unNeedReply;
	}

	public void setUnNeedReply(Short unNeedReply) {
		this.unNeedReply = unNeedReply;
	}

	/**
	 * 获取所有可以搜索的字段列名（索引的field名）
	 * 
	 * @return 可以搜索的字段列名
	 */
	public static List<String> getKeywordFields() {
		List<String> fields = new ArrayList<>();
		fields.add(CODE_FIELD);
		fields.add(VEND_FIELD);
		fields.add(ITEMS_FIELD);
		fields.add(ORDERCODE_FIELD);
		fields.add(ENTERPRISE_FIELD);
		return fields;
	}

	@Override
	public String toString() {
		return "PurchaseChangesSimpleInfo [id=" + id + ", date=" + date + ", enterprise=" + enterprise + ", vend="
				+ vend + ", code=" + code + ", status=" + status + ", orderCode=" + orderCode + ", orderChangeItems="
				+ orderChangeItems + ", unNeedReply=" + unNeedReply + "]";
	}

}