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;

@Table(name = PurchaseForecastSimpleInfo.TABLE_NAME)
@Entity
public class PurchaseForecastSimpleInfo {

	/**
	 * 表名
	 */
	// 每个主表必须与com.uas.search.b2b.service.SearchService.Table_name对应的单据类型的value保持一致
	public static final String TABLE_NAME = "PURC$FORECAST";

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

	public static final String CODE_FIELD = "pf_code";

	public static final String DATE_FIELD = "pf_date";

	public static final String VEND_FIELD = "pf_enuu";

	public static final String ITEMS_FIELD = "pfd_pfid";

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

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

	/**
	 * 供应商 采购预测单所属企业UU
	 */
	@OneToOne
	@JoinColumn(name = VEND_FIELD, insertable = false, updatable = false)
	private EnterpriseSimpleInfo vend;

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

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

	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 Date getDate() {
		return date;
	}

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

	public Set<PurchaseForecastItemSimpleInfo> getForecastItems() {
		return forecastItems;
	}

	public void setForecastItems(Set<PurchaseForecastItemSimpleInfo> forecastItems) {
		this.forecastItems = forecastItems;
	}

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

	@Override
	public String toString() {
		return "PurchaseForecastSimpleInfo [id=" + id + ", date=" + date + ", vend=" + vend + ", code=" + code
				+ ", forecastItems=" + forecastItems + "]";
	}

}
