package com.github.microservice.components.data.mongo.queue.domain;

import com.github.microservice.components.data.mongo.mongo.domain.SuperEntity;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.Date;
import java.util.Map;

@Data
@Document
@NoArgsConstructor
@AllArgsConstructor
public class ExecQueue extends SuperEntity {

    @Indexed
    private long nextTime;


    //尝试次数
    @Indexed
    private int maxTryCount;

    //尝试次数
    @Indexed
    private int currentTryCount;

    // 数据
    private Map<String, Object> data;


    // 处理事件的代码
    private byte[] execQueueEvent;

    //状态
    @Indexed
    private ExecQueueStatus status;


    // 正在执行的时间，如果超时则需要重置等待队列
    @Indexed
    private long workTime;

    // 过期时间
    @Indexed(expireAfterSeconds = 0)
    private Date TTL;


    /**
     * 队列的状态
     */
    public enum ExecQueueStatus {

        Wait("等待中"),

        Work("进行中"),

        Done("完成"),

        Stop("停止"),

        ;

        ExecQueueStatus(String name) {
            this.name = name;
        }

        @Getter
        private String name;


    }


}
