import { apiKeys, contextCache, workAppGitHubMcpToolAccessMode, workAppGitHubMcpToolRepositoryAccess, workAppSlackChannelAgentConfigs, workAppSlackMcpToolAccessConfig } from "../../db/runtime/runtime-schema.js";
import { projectScopedWhere } from "../manage/scope-helpers.js";

//#region src/data-access/runtime/audit-queries.ts
const listGitHubToolAccessByProject = (db) => async (params) => {
	return db.select({
		id: workAppGitHubMcpToolRepositoryAccess.id,
		toolId: workAppGitHubMcpToolRepositoryAccess.toolId
	}).from(workAppGitHubMcpToolRepositoryAccess).where(projectScopedWhere(workAppGitHubMcpToolRepositoryAccess, params.scopes));
};
const listGitHubToolAccessModeByProject = (db) => async (params) => {
	return db.select({ toolId: workAppGitHubMcpToolAccessMode.toolId }).from(workAppGitHubMcpToolAccessMode).where(projectScopedWhere(workAppGitHubMcpToolAccessMode, params.scopes));
};
const listSlackToolAccessConfigByProject = (db) => async (params) => {
	return db.select({ toolId: workAppSlackMcpToolAccessConfig.toolId }).from(workAppSlackMcpToolAccessConfig).where(projectScopedWhere(workAppSlackMcpToolAccessConfig, params.scopes));
};
const listContextCacheByProject = (db) => async (params) => {
	return db.select({
		id: contextCache.id,
		contextConfigId: contextCache.contextConfigId
	}).from(contextCache).where(projectScopedWhere(contextCache, params.scopes));
};
const listApiKeysByProject = (db) => async (params) => {
	return db.select({
		id: apiKeys.id,
		agentId: apiKeys.agentId
	}).from(apiKeys).where(projectScopedWhere(apiKeys, params.scopes));
};
const listSlackChannelAgentConfigsByProject = (db) => async (params) => {
	return db.select({
		id: workAppSlackChannelAgentConfigs.id,
		agentId: workAppSlackChannelAgentConfigs.agentId
	}).from(workAppSlackChannelAgentConfigs).where(projectScopedWhere(workAppSlackChannelAgentConfigs, params.scopes));
};

//#endregion
export { listApiKeysByProject, listContextCacheByProject, listGitHubToolAccessByProject, listGitHubToolAccessModeByProject, listSlackChannelAgentConfigsByProject, listSlackToolAccessConfigByProject };