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

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.annotation.MainKey;
import cn.estsh.i3plus.pojo.aps.annotation.RippleAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BaseAPS;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EMaterial;
import cn.estsh.i3plus.pojo.aps.validator.InsertGroup;
import cn.estsh.i3plus.pojo.aps.validator.UpdateGroup;
import cn.estsh.i3plus.pojo.base.enumutil.ApsEnumUtil;
import com.fasterxml.jackson.annotation.JsonBackReference;
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;
import java.util.List;

/**
 * @Description :物料
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-09-17
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_MATERIAL")
@Api("物料")
@MainKey(groups = {InsertGroup.class, UpdateGroup.class})
public class Material extends BaseAPS {
    private static final long serialVersionUID = -7928225487946173108L;
    @Column(name="CODE")
    @ApiParam(value ="编码")
    @FieldAnnotation(popSearch = true, mainkey = true)
    private String code;

    @Column(name="NAME")
    @ApiParam(value ="名称")
    @FieldAnnotation(popSearch = true)
    private String name;

    @Column(name="TYPE")
    @ApiParam(value ="物料类型")
    @FieldAnnotation(defaultValue = "PRODUCT")
    private ApsEnumUtil.MATERIAL_TYPE type;

    @Column(name="PREPARE_TYPE")
    @ApiParam(value ="备料类型")
    @FieldAnnotation(defaultValue = "SELF_MAKE")
    private ApsEnumUtil.PREPARE_TYPE prepareType;

    @Column(name="REPL_TYPE")
    @ApiParam(value ="补充类型")
    @FieldAnnotation(defaultValue = "ONEBYONE")
    private ApsEnumUtil.REPLENISHMENT_TYPE replType;

    @Column(name="PURCHASE_LEAD_TIME")
    @ApiParam(value ="采购提前期")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String purchaseLeadTime;

    @Column(name="PRODUCT_LEAD_TIME")
    @ApiParam(value ="生产提前期")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String productLeadTime;

    @Column(name="SHIPMENT_LEAD_TIME")
    @ApiParam(value ="配送提前期")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String shipmentLeadTime;

    @Column(name="UNIT_PURCHASE")
    @ApiParam(value ="单位采购量")
    private Integer unitPurchase;

    @Column(name="UNIT_PRODUCT")
    @ApiParam(value ="单位生产量")
    private Integer unitProduct;

    @Column(name="UNIT_SHIPMENT")
    @ApiParam(value ="单位配送量")
    private Integer unitShipment;

    @Column(name="LEVEL")
    @ApiParam(value ="低阶码")
    @RippleAnnotation(dependence = {"OperInputs.Operation.ProductRouting.Material.level"}, method = "calcLevel")
    @FieldAnnotation(modify = false)
    private Integer level;

    @Column(name="IS_AUTO_FIX_PEGGING")
    @ApiParam(value ="自动补充标识")
    @FieldAnnotation(defaultValue = "1")
    private Boolean autoFixPegging;

    @Column(name="MAX_PRODUCT_BATCH", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="最大生产批量")
    private Double maxProductBatch;

    @Column(name="MIN_PRODUCT_BATCH", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="最小生产批量")
    @FieldAnnotation(defaultValue = "0.0")
    private Double minProductBatch;

    @Column(name="UNIT_PRODUCT_BATCH", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="生产批量单位")
    private Double unitProductBatch;

    @Column(name="MAX_PUR_BATCH", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="最大采购批量")
    private Double maxPurBatch;

    @Column(name="MIN_PUR_BATCH", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="最小采购批量")
    private Double minPurBatch;

    @Column(name="UNIT_PUR_BATCH", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="采购批量单位")
    private Double unitPurBatch;

    @Column(name="MIN_STOCK_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="最小库存数量")
    @FieldAnnotation(property = false)
    private Double minStockCount;

    @Column(name="SAFE_STOCK_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="安全库存数量")
    @FieldAnnotation(property = false)
    private Double safeStockCount;

    @Column(name="MAX_STOCK_COUNT", columnDefinition = "decimal(18,8)")
    @ApiParam(value ="最大库存数量")
    @FieldAnnotation(property = false)
    private Double maxStockCount;

    @Column(name="ORDER_BATCH_PERIOD")
    @ApiParam(value ="订单合并期间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String orderBatchPeriod;

    @Column(name="LABEL_NAME")
    @ApiParam(value ="标签名称")
    private String labelName;

    @Column(name="LABEL_COLOR")
    @ApiParam(value ="标签颜色")
    private String labelColor;

    @JsonBackReference
    public List<ProductRouting> getProductRoutings() {
        return BeanRelation.list(this, EMaterial.ProductRoutings);
    }

    @JsonBackReference
    public List<OperInput> getOperInputs() {
        return BeanRelation.list(this, EMaterial.OperInputs);
    }

    @JsonBackReference
    public List<OperOutput> getOperOutputs() {
        return BeanRelation.list(this, EMaterial.OperOutputs);
    }

    @JsonBackReference
    public List<WorkInput> getWorkInputs() {
        return BeanRelation.list(this, EMaterial.WorkInputs);
    }

    @JsonBackReference
    public List<WorkOutput> getWorkOutputs() {
        return BeanRelation.list(this, EMaterial.WorkOutputs);
    }

    @JsonBackReference
    public List<WorkRelation> getWorkRelations() {
        return BeanRelation.list(this, EMaterial.WorkRelations);
    }

    @JsonBackReference
    public List<BaseOrder> getOrders() {
        return BeanRelation.list(this, EMaterial.Orders);
    }

    @JsonBackReference
    public List<SalesOrder> getSalesOrder() {
        return BeanRelation.listByClass(this, SalesOrder.class, EMaterial.Orders);
    }

    @JsonBackReference
    public List<PurchaseOrder> getPurchaseOrders() {
        return BeanRelation.listByClass(this, PurchaseOrder.class, EMaterial.Orders);
    }

    @JsonBackReference
    public List<Inventory> getInventories() {
        return BeanRelation.listByClass(this, Inventory.class, EMaterial.Orders);
    }

    @JsonBackReference
    public List<ProductOrder> getProductOrders() {
        return BeanRelation.listByClass(this, ProductOrder.class, EMaterial.Orders);
    }
}
