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.common.BaseAPS;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EProductRouting;
import cn.estsh.i3plus.pojo.aps.validator.InsertGroup;
import cn.estsh.i3plus.pojo.aps.validator.UpdateGroup;
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.Date;
import java.util.List;

/**
 * @Description :工艺路线
 * @Reference :
 * @Author : jason.niu
 * @CreateDate : 2019-09-17
 * @Modify:
 **/
@Data
@EqualsAndHashCode(callSuper = true)
@Entity
@Table(name = "APS_PRODUCT_ROUTING")
@Api("工艺路线")
@MainKey(groups = {InsertGroup.class, UpdateGroup.class})
public class ProductRouting extends BaseAPS {
    private static final long serialVersionUID = 4905294866468216722L;
    @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="MATERIAL_ID")
    @ApiParam(value ="物料")
    @FieldAnnotation(relation = "Material", notEmpty = true, display = false)
    private Long materialId;

    @Column(name="VALID_START")
    @ApiParam(value ="有效开始时间")
    private Date validStart;

    @Column(name="VALID_END")
    @ApiParam(value ="有效结束时间")
    private Date validEnd;

    @Column(name="PRIORITY")
    @ApiParam(value ="优先级")
    @FieldAnnotation(defaultValue = "10")
    private Integer priority;

    public Material getMaterial() {
        return BeanRelation.get(this, EProductRouting.Material);
    }

    public void setMaterial(Material material) {
        this.materialId = material != null ? material.getId() : 0l;
        BeanRelation.set(this, EProductRouting.Material, material);
    }

    @JsonBackReference
    public List<Operation> getOperations() {
        return BeanRelation.list(this, EProductRouting.Operations);
    }

    @JsonBackReference
    public List<ProductOrder> getProductOrders() {
        return BeanRelation.list(this, EProductRouting.ProductOrders);
    }
}
