package com.easyagents.scheduler;

import java.time.Instant;
import java.util.Objects;

/**
 * 立即触发请求已被调度器接受的回执。
 *
 * @param scheduleId 任务标识
 * @param invocationId 调用方提供的链路标识
 * @param acceptedAt 调度器接受请求的时间
 */
public record ScheduleFireReceipt(
    ScheduleId scheduleId,
    String invocationId,
    Instant acceptedAt
) {

    /**
     * 校验并创建立即触发回执。
     *
     * @throws IllegalArgumentException 调用标识为空时抛出
     * @throws NullPointerException 任务标识或接受时间为空时抛出
     */
    public ScheduleFireReceipt {
        scheduleId = Objects.requireNonNull(scheduleId, "scheduleId must not be null");
        acceptedAt = Objects.requireNonNull(acceptedAt, "acceptedAt must not be null");
        if (invocationId == null || invocationId.isBlank()) {
            throw new IllegalArgumentException("invocationId must not be blank");
        }
        invocationId = invocationId.trim();
    }
}
