package cn.axzo.workflow.es.model;

import cn.axzo.workflow.es.setting.CustomIndexSettingProvider;
import lombok.Data;
import org.dromara.easyes.annotation.IndexField;
import org.dromara.easyes.annotation.IndexId;
import org.dromara.easyes.annotation.IndexName;
import org.dromara.easyes.annotation.Join;
import org.dromara.easyes.annotation.Node;
import org.dromara.easyes.annotation.Settings;
import org.dromara.easyes.annotation.rely.FieldType;
import org.dromara.easyes.annotation.rely.IdType;
import org.dromara.easyes.annotation.rely.RefreshPolicy;

import java.util.Date;

import static org.dromara.easyes.annotation.rely.Analyzer.IK_MAX_WORD;

/**
 * 流程实例文档模型
 *
 * @author wangli
 * @since 2024-09-25 20:32
 */
@Data
@Settings(settingsProvider = CustomIndexSettingProvider.class, replicasNum = 1, shardsNum = 1)
@IndexName(value = "process_instance_document", keepGlobalPrefix = true, refreshPolicy = RefreshPolicy.NONE)
@Join(nodes = {@Node(parentClass = ProcessInstanceDocument.class, parentAlias = "process_instance_document", childClasses = {ProcessTaskDocument.class}, childAliases = {"process_task_document"})})
public class ProcessInstanceDocument {

    /**
     * 流程实例 ID
     */
    @IndexId(type = IdType.CUSTOMIZE)
    private String id;

    @IndexField(fieldType = FieldType.KEYWORD)
    private String instanceId;

    /**
     * 流程实例名称
     */
    @IndexField(fieldType = FieldType.KEYWORD_TEXT, analyzer = IK_MAX_WORD, searchAnalyzer = IK_MAX_WORD)
    private String processInstanceName;

    /**
     * 业务传入业务信息
     */
    private String businessKey;

    /**
     * 流程实例使用的定义 ID
     */
    private String processDefinitionId;

    /**
     * 流程对应业务分类的类型,项目/单位/监管/OMS
     */
    @IndexField(fieldType = FieldType.KEYWORD)
    private String processCategoryType;

    /**
     * 流程实例的发起时间
     */
    @IndexField(dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
    private Date instanceStartTime;

    /**
     * 流程实例的结束时间
     */
    @IndexField(dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
    private Date instanceEndTime;

    /**
     * 流程实例的持续时间 ms
     */
    private Long durationInMillis;

    /**
     * 该流程中上次操作完成的时间, 如果是已完成的实例, 就清空该值
     */
    @IndexField(dateFormat = "yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis")
    private Date lastOperationTime;

    /**
     * 租户 ID
     */
    @IndexField(fieldType = FieldType.KEYWORD)
    private String instanceTenantId;

    /**
     * 流程实例业务状态
     */
    @IndexField(fieldType = FieldType.KEYWORD)
    private String businessStatus;

    /**
     * 发起人姓名
     */
    @IndexField(fieldType = FieldType.KEYWORD)
    private String initiatorName;

    /**
     * 发起人模型
     */
    @IndexField(fieldType = FieldType.TEXT)
    private String initiatorJsonStr;

    /**
     * 实例对应的流程引擎服务端迭代版本
     */
    @IndexField(fieldType = FieldType.KEYWORD)
    private String workflowEngineVersion;

    /**
     * 是否代运营
     */
    private Boolean agent;

    /**
     * 是否支持批量操作任务
     */
    private Boolean supportBatch;

    /**
     * 是否开启同意操作时的签名
     */
    private Boolean userAgreeSignature;
}
