package cn.estsh.i3plus.pojo.aps.bean;

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EBaseOrder;
import cn.estsh.i3plus.pojo.aps.holders.ESafeStockOrder;
import cn.estsh.i3plus.pojo.base.enumutil.ApsEnumUtil;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Table;

/**
 * @Description :安全库存订单
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2021-02-23
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_SAFE_STOCK_ORDER")
@Api("安全库存订单")
public class SafeStockOrder extends BaseOrder {

    private static final long serialVersionUID = 5944067344390531794L;

    @Column(name="ORDER_STATUS")
    @ApiParam(value ="订单状态")
    @FieldAnnotation(defaultValue = "UNCOMMIT")
    private ApsEnumUtil.SAFE_STOCK_ORDER_STATUS orderStatus = ApsEnumUtil.SAFE_STOCK_ORDER_STATUS.UNCOMMIT;

    @Column(name="INVENTORY_ID")
    @ApiParam(value ="库存")
    @FieldAnnotation(relation = "Inventory", notEmpty = true)
    private Long inventoryId;

    @Column(name="FINISH_COUNT")
    @ApiParam(value ="完工数")
    private Double finishCount;

    @JsonIgnore
    public Work getWork() {
        return BeanRelation.get(this, EBaseOrder.Works);
    }

    public Inventory getInventory() { return BeanRelation.get(this, ESafeStockOrder.Inventory); }

    public void setInventory(Inventory inventory) {
        this.inventoryId = inventory != null ? inventory.getId() : 0;
        BeanRelation.set(this, ESafeStockOrder.Inventory, inventory);
    }
}
