package com.gzzm.lobster.tool.mcp;

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

import java.util.List;

public abstract class McpToolCacheDao extends GeneralDao {

    @OQL("select t from McpToolCache t where t.toolKey=:1")
    public abstract McpToolCache getByKey(String toolKey) throws Exception;

    @OQL("select t from McpToolCache t where t.localToolName=:1")
    public abstract McpToolCache getByLocalToolName(String localToolName) throws Exception;

    @OQL("select t from McpToolCache t where t.serverId=:1 order by t.localToolName asc")
    public abstract List<McpToolCache> listByServer(String serverId) throws Exception;

    @OQL("select t from McpToolCache t where t.serverId=:1 and t.enabled=:2 order by t.localToolName asc")
    public abstract List<McpToolCache> listByServerAndEnabled(String serverId, Boolean enabled) throws Exception;

    @OQL("select t from McpToolCache t order by t.serverId asc, t.localToolName asc limit :1,:2")
    public abstract List<McpToolCache> listAll(int offset, int limit) throws Exception;

    @OQL("select t from McpToolCache t where t.enabled=:1 order by t.serverId asc, t.localToolName asc limit :2,:3")
    public abstract List<McpToolCache> listAllByEnabled(Boolean enabled, int offset, int limit) throws Exception;

    @OQL("select count(t) from McpToolCache t")
    public abstract long countAll() throws Exception;

    @OQL("select count(t) from McpToolCache t where t.enabled=:1")
    public abstract long countByEnabled(Boolean enabled) throws Exception;

    @OQLUpdate("delete from McpToolCache where serverId=?1")
    public abstract int deleteByServer(String serverId) throws Exception;
}
