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

import cn.estsh.i3plus.pojo.aps.annotation.FieldAnnotation;
import cn.estsh.i3plus.pojo.aps.common.BaseAPS;
import cn.estsh.i3plus.pojo.aps.common.BeanRelation;
import cn.estsh.i3plus.pojo.aps.holders.EOperResource;
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_OPER_RESOURCE")
@Api("工序资源")
public class OperResource extends BaseAPS {
    private static final long serialVersionUID = -8683889582369342606L;
    @Column(name="OPERATION_ID")
    @ApiParam(value ="工序")
    @FieldAnnotation(relation = "Operation", notEmpty = true, display = false)
    private Long operationId;

    @Column(name="RESOURCE_ID")
    @ApiParam(value ="资源")
    @FieldAnnotation(relation = "Resource", notEmpty = true)
    private Long resourceId;

    @Column(name="USE_TYPE")
    @ApiParam(value ="使用类型")
    @FieldAnnotation(defaultValue = "MAIN")
    private ApsEnumUtil.USE_TYPE useType;

    @Column(name="PREV_TIME")
    @ApiParam(value ="前设置时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String prevTime;

    @Column(name="PRODUCE_TIME")
    @ApiParam(value ="生产时间")
    @FieldAnnotation(notEmpty = true, editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String produceTime;

    @Column(name="POST_TIME")
    @ApiParam(value ="后设置时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String postTime;

    @Column(name="MAX_PREV_SD_TIME")
    @ApiParam(value ="最大前设置中断时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String maxPrevSdTime;

    @Column(name="MAX_PRODUCE_SD_TIME")
    @ApiParam(value ="最大生产中断时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String maxProduceSdTime;

    @Column(name="MAX_POST_SD_TIME")
    @ApiParam(value ="最大后设置中断时间")
    @FieldAnnotation(editType = ApsEnumUtil.EDIT_TYPE.DURATION)
    private String maxPostSdTime;

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

    @Column(name="USER_MATCH_NUMBER")
    @ApiParam(value ="资源使用配套号")
    private String userMatchNumber;

    public Operation getOperation() {
        return BeanRelation.get(this, EOperResource.Operation);
    }

    public void setOperation(Operation oper) {
        this.operationId = oper != null ? oper.getId() : 0l;
        BeanRelation.set(this, EOperResource.Operation, oper);
    }

    public Resource getResource() {
        return BeanRelation.get(this, EOperResource.Resource);
    }

    public void setResource(Resource res) {
        this.resourceId = res != null ? res.getId() : 0l;
        BeanRelation.set(this, EOperResource.Resource, res);
    }

    @JsonBackReference
    public List<WorkResource> getWorkResources() {
        return BeanRelation.list(this, EOperResource.WorkResources);
    }
}
