package com.easyagents.document.core.async;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * 基于内存的异步任务仓库。
 *
 * @author Codex
 * @since 2026-04-16
 */
public class InMemoryDocumentAsyncTaskRepository implements DocumentAsyncTaskRepository {

    private final Map<String, DocumentAsyncTaskRecord> records = new ConcurrentHashMap<String, DocumentAsyncTaskRecord>();

    @Override
    public void save(DocumentAsyncTaskRecord record) {
        if (record == null || record.getStatusSnapshot() == null || record.getStatusSnapshot().getTaskId() == null) {
            return;
        }
        records.put(record.getStatusSnapshot().getTaskId(), record);
    }

    @Override
    public DocumentAsyncTaskRecord find(String taskId) {
        return records.get(taskId);
    }
}
