package com.gzzm.lobster.tool;

import net.cyan.thunwind.annotation.OQL;
import net.cyan.thunwind.annotation.OQLUpdate;
import net.cyan.thunwind.dao.GeneralDao;

import java.util.Date;
import java.util.List;

/**
 * Persistence for durable tool-call lifecycle records.
 */
public abstract class ToolExecutionRecordDao extends GeneralDao {

    @OQL("select r from ToolExecutionRecord r where r.runId=:1 and r.toolCallId=:2 order by r.startedAt desc")
    public abstract List<ToolExecutionRecord> listByRunAndCall(String runId, String toolCallId) throws Exception;

    @OQLUpdate("update ToolExecutionRecord set status=?1, resultJson=?2, errorMessage=?3, durationMs=?4, finishedAt=?5 where executionId=?6")
    public abstract int finish(String status, String resultJson, String errorMessage,
                               Long durationMs, Date finishedAt, String executionId) throws Exception;
}
