package com.greenorange.promotion.utils;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serial;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@Data
@NoArgsConstructor
public class MultiDelayMessage<T> implements Serializable {

    /**
     * 消息体
     */
    private T data;


    /**
     * 记录延时时间的集合
     */
    private List<Long> delayMillis;

    public MultiDelayMessage(T data, List<Long> delayMillis) {
        this.data = data;
        this.delayMillis = delayMillis;
    }

    public MultiDelayMessage(T data, Long...delayMillis) {
        this.data = data;
        this.delayMillis = new ArrayList<>(Arrays.asList(delayMillis));
    }

    /**
     * 获取并移除下一个延迟时间
     * @return 集合中第一个延迟时间
     */
    public Long removeNextDelay() {
        return delayMillis.remove(0);
    }


    /**
     * 是否有下一个延迟时间
     */
    public boolean hasNextDelay() {
        return !delayMillis.isEmpty();
    }



    @Serial
    private static final long serialVersionUID = 1L;


}
