export class JobQueue {
    state;
    constructor(state) {
        this.state = state;
    }
    enqueue(kind, payload, options = {}) {
        const id = this.state.createJob({
            kind,
            payload,
            runId: options.runId,
            maxAttempts: options.maxAttempts,
        });
        const job = this.state.getJob(id);
        if (!job)
            throw new Error(`job not found after enqueue: ${id}`);
        return job;
    }
    claim(input = {}) {
        return this.state.claimNextJob({
            kind: input.kind,
            runId: input.runId,
            claimant: input.claimant ?? "job-queue",
        });
    }
    finish(id, status) {
        this.state.finishJob(id, status);
    }
    retry(id, detail = "retry requested") {
        return this.state.retryJob(id, detail);
    }
    list(input = {}) {
        return this.state.listJobs(input);
    }
}
