package com.gzzm.lobster.audit;

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

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

/**
 * ModelCallLogDao —— 模型调用日志持久化 / Model call log persistence.
 */
public abstract class ModelCallLogDao extends GeneralDao {

    @OQL("select c from ModelCallLog c where c.callId=:1")
    public abstract ModelCallLog getCall(String callId) throws Exception;

    @OQL("select c from ModelCallLog c where c.runId=:1 order by c.createTime asc")
    public abstract List<ModelCallLog> listByRun(String runId) throws Exception;

    @OQL("select c from ModelCallLog c where c.runId=:1 order by c.createTime asc limit :2,:3")
    public abstract List<ModelCallLog> listByRun(String runId, int offset, int limit) throws Exception;

    @OQL("select count(c) from ModelCallLog c where c.runId=:1")
    public abstract long countByRun(String runId) throws Exception;

    @OQL("select c from ModelCallLog c where c.threadId=:1 order by c.createTime desc limit :2,:3")
    public abstract List<ModelCallLog> listByThread(String threadId, int offset, int limit) throws Exception;

    @OQL("select count(c) from ModelCallLog c where c.threadId=:1")
    public abstract long countByThread(String threadId) throws Exception;

    @OQL("select c from ModelCallLog c order by c.createTime desc limit :1,:2")
    public abstract List<ModelCallLog> listAll(int offset, int limit) throws Exception;

    @OQL("select count(c) from ModelCallLog c")
    public abstract long countAll() throws Exception;

    @OQL("select count(c.callId) from ModelCallLog c where c.userId=:1 and c.createTime>=?2")
    public abstract Long countCallsSince(String userId, Date since) throws Exception;
}
