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

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

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

/**
 * 买家MRB单
 * 
 * @author suntg
 *
 */
@Table(name = PurchaseMrbSimpleInfo.TABLE_NAME)
@Entity
public class PurchaseMrbSimpleInfo {

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

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

	public static final String CODE_FIELD = "pm_code";

	public static final String ENTERPRISE_FIELD = "pm_enuu";

	public static final String DATE_FIELD = "pm_date";

	public static final String SENDCODE_FIELD = "pm_sendcode";

	public static final String VEND_FIELD = "pm_venduu";

	public static final String ITEMS_FIELD = "pm_pdid";

	public static final String BADITEMS_FIELD = "pm_pbid";

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

	/**
	 * 单号
	 */
	@Column(name = CODE_FIELD)
	private String code;

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

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

	/**
	 * 供应商
	 */
	@OneToOne
	@JoinColumn(name = VEND_FIELD, insertable = false, updatable = false)
	private EnterpriseSimpleInfo vend;

	/**
	 * 采购订单明细
	 */
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = ITEMS_FIELD, insertable = false, updatable = false)
	private PurchaseOrderItemSimpleInfo orderItem;

	/**
	 * 不良品入库单
	 */
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = BADITEMS_FIELD, insertable = false, updatable = false)
	private PurchaseBadinSimpleInfo badIn;

	/**
	 * 收货单号
	 */
	@Column(name = SENDCODE_FIELD)
	private String sendCode;

	public Long getId() {
		return id;
	}

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

	public String getCode() {
		return code;
	}

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

	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 EnterpriseSimpleInfo getVend() {
		return vend;
	}

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

	public PurchaseOrderItemSimpleInfo getOrderItem() {
		return orderItem;
	}

	public void setOrderItem(PurchaseOrderItemSimpleInfo orderItem) {
		this.orderItem = orderItem;
	}

	public PurchaseBadinSimpleInfo getBadIn() {
		return badIn;
	}

	public void setBadIn(PurchaseBadinSimpleInfo badIn) {
		this.badIn = badIn;
	}

	public String getSendCode() {
		return sendCode;
	}

	public void setSendCode(String sendCode) {
		this.sendCode = sendCode;
	}

	/**
	 * 获取所有可以搜索的字段列名（索引的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(SENDCODE_FIELD);
		fields.add(BADITEMS_FIELD);
		return fields;
	}

	@Override
	public String toString() {
		return "PurchaseMrbSimpleInfo [id=" + id + ", code=" + code + ", date=" + date + ", enterprise=" + enterprise
				+ ", vend=" + vend + ", orderItem=" + orderItem + ", badIn=" + badIn + ", sendCode=" + sendCode + "]";
	}

}