package cn.axzo.workflow.common.model.request.bpmn.task;

import cn.axzo.workflow.common.constraint.AttachmentTypeValidator;
import cn.axzo.workflow.common.constraint.AttachmentValidator;
import cn.axzo.workflow.common.enums.AttachmentTypeEnum;
import cn.axzo.workflow.common.enums.BpmnCountersignTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import java.io.Serializable;
import java.util.List;


/**
 * 统一的工作流中的人员模型,兼容不同的业务方,如安心筑"唯一"人的定义需要工作台+身份 ID+身份类型;而枢智业务则只需要简单的 userId 即可
 * <p>
 * 为了解决各种业务的差异,统一定义该模型,已大范围覆盖小范围的方式进行兼容.
 *
 * @author zuoqinbo
 */
@Data
@Accessors(chain = true)
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class BpmnTaskCountersignDTO implements Serializable {

    private static final long serialVersionUID = -8106887960942113552L;

    /**
     * 流程实例 ID
     * <p>
     * 与审批任务 ID 二选一
     */
    @ApiModelProperty(value = "流程实例编号", required = true, example = "1024")
    private String processInstanceId;

    /**
     * 审批任务 ID
     * <p>
     * 与流程实例 ID 二选一，如果两属性都传，则优先使用 taskId
     */
    @ApiModelProperty(value = "任务编号", required = true, example = "1024")
    private String taskId;

    /**
     * 加签类型
     * 向前加签、向后加签
     *
     * @see BpmnCountersignTypeEnum
     */
    @ApiModelProperty(value = "加签类型")
    @NotEmpty(message = "加签类型不能为空")
    private String countersignType = "SHARE_COUNTERSIGN";

    /**
     * 加签意见
     */
    @ApiModelProperty(value = "加签意见")
    private String advice;

    /**
     * 附件列表
     */
    @ApiModelProperty(value = "附件列表")
    @Size(max = 11, message = "附件数量超过限制")
    @AttachmentValidator(types = {
            @AttachmentTypeValidator(type = AttachmentTypeEnum.image, max = 5),
            @AttachmentTypeValidator(type = AttachmentTypeEnum.file, max = 5),
            @AttachmentTypeValidator(type = AttachmentTypeEnum.signature, max = 1)}
    )
    private List<AttachmentDTO> attachmentList;

    /**
     * 加签任务转发给谁
     */
    @ApiModelProperty(value = "加签任务转发给谁")
    @NotEmpty(message = "加签任务接收人不能为空")
    private List<BpmnTaskDelegateAssigner> targetAssignerList;

    /**
     * 加签任务原发起人
     */
    @ApiModelProperty(value = "加签任务原发起人")
    @Valid
    @NotNull(message = "加签任务发起人不能为空")
    private BpmnTaskDelegateAssigner originAssigner;

    /**
     * 是否异步执行
     */
    @ApiModelProperty(value = "是否异步", notes = "异步时,只接收请求便返回数据")
    @Builder.Default
    private Boolean async = true;

}
