package com.gzzm.lobster.tool;

import net.cyan.thunwind.annotation.ColumnDescription;
import net.cyan.thunwind.annotation.Entity;
import net.cyan.thunwind.annotation.Index;

import java.util.Date;

/**
 * Durable lifecycle record for one model-issued tool call.
 *
 * <p>This is separate from audit logs: audit answers "who did what"; this
 * record answers "which tool call is safe to resume, replay, or diagnose" after
 * a backend restart.
 */
@Entity(table = "AI_TOOL_EXECUTION_RECORD", keys = "executionId")
public class ToolExecutionRecord {

    @ColumnDescription(type = "varchar(40)")
    private String executionId;

    @Index
    @ColumnDescription(type = "varchar(40)", nullable = false)
    private String runId;

    @Index
    @ColumnDescription(type = "varchar(40)", nullable = false)
    private String threadId;

    @Index
    @ColumnDescription(type = "varchar(80)")
    private String toolCallId;

    @ColumnDescription(type = "varchar(220)", nullable = false)
    private String toolName;

    @ColumnDescription(type = "varchar(40)")
    private String sideEffect;

    @ColumnDescription(type = "varchar(40)", nullable = false)
    private String status;

    @ColumnDescription(type = "clob")
    private String argumentsJson;

    @ColumnDescription(type = "clob")
    private String resultJson;

    @ColumnDescription(type = "varchar(2000)")
    private String errorMessage;

    @ColumnDescription(type = "number(12)")
    private Long durationMs;

    private Date startedAt;
    private Date finishedAt;

    public String getExecutionId() { return executionId; }
    public void setExecutionId(String executionId) { this.executionId = executionId; }
    public String getRunId() { return runId; }
    public void setRunId(String runId) { this.runId = runId; }
    public String getThreadId() { return threadId; }
    public void setThreadId(String threadId) { this.threadId = threadId; }
    public String getToolCallId() { return toolCallId; }
    public void setToolCallId(String toolCallId) { this.toolCallId = toolCallId; }
    public String getToolName() { return toolName; }
    public void setToolName(String toolName) { this.toolName = toolName; }
    public String getSideEffect() { return sideEffect; }
    public void setSideEffect(String sideEffect) { this.sideEffect = sideEffect; }
    public String getStatus() { return status; }
    public void setStatus(String status) { this.status = status; }
    public String getArgumentsJson() { return argumentsJson; }
    public void setArgumentsJson(String argumentsJson) { this.argumentsJson = argumentsJson; }
    public String getResultJson() { return resultJson; }
    public void setResultJson(String resultJson) { this.resultJson = resultJson; }
    public String getErrorMessage() { return errorMessage; }
    public void setErrorMessage(String errorMessage) { this.errorMessage = errorMessage; }
    public Long getDurationMs() { return durationMs; }
    public void setDurationMs(Long durationMs) { this.durationMs = durationMs; }
    public Date getStartedAt() { return startedAt; }
    public void setStartedAt(Date startedAt) { this.startedAt = startedAt; }
    public Date getFinishedAt() { return finishedAt; }
    public void setFinishedAt(Date finishedAt) { this.finishedAt = finishedAt; }
}
