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;

/**
 * 买家应付对账单
 * 
 * @author suntg
 * @date 2015年10月10日16:42:27
 */
@Table(name = SaleArcheckSimpleInfo.TABLE_NAME)
@Entity
public class SaleArcheckSimpleInfo {

	/**
	 * 表名
	 */
	public static final String TABLE_NAME = "SALE$ARCHECK";

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

	public static final String CODE_FIELD = "sac_code";

	public static final String VEND_FIELD = "sac_venduu";

	public static final String STATUS_FIELD = "sac_status";

	public static final String ITEMS_FIELD = "saci_sacid";

	public static final String ENTERPRISE_FIELD = "sac_enuu";

	public static final String DATE_FIELD = "sac_date";

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

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

	/**
	 * 状态 200-还没开始回复对账 201-已开始回复对账
	 */
	@Column(name = "sac_status")
	private Short status;

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

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

	/**
	 * 采购企业
	 */
	@OneToOne(cascade = { CascadeType.REFRESH })
	@JoinColumn(name = VEND_FIELD, insertable = false, updatable = false)
	private EnterpriseSimpleInfo vendor;

	/**
	 * 对账的单明细行
	 */
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.EAGER)
	@JoinColumn(name = ITEMS_FIELD, insertable = false, updatable = false)
	private Set<SaleARCheckItemSimpleInfo> items;

	public Long getId() {
		return id;
	}

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

	public Short getStatus() {
		return status;
	}

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

	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 getVendor() {
		return vendor;
	}

	public void setVendor(EnterpriseSimpleInfo vendor) {
		this.vendor = vendor;
	}

	public Set<SaleARCheckItemSimpleInfo> getItems() {
		return items;
	}

	public void setItems(Set<SaleARCheckItemSimpleInfo> items) {
		this.items = items;
	}

	/**
	 * 获取除了status外的所有字段的列名（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 "SaleArcheckSimpleInfo [id=" + id + ", code=" + code + ", status=" + status + ", date=" + date
				+ ", enterprise=" + enterprise + ", vendor=" + vendor + ", items=" + items + "]";
	}

}