export { DbLogsAPIResponseSchema, DbLogsRequestSchema, DbLogsResponseSchema, DbQueryLogSchema, dbLogs, } from "./logs.js";
export { DbLogStatsAPIResponseSchema, DbLogStatsCommandBreakdownSchema, DbLogStatsQueryPatternSchema, DbLogStatsRequestSchema, DbLogStatsResponseSchema, DbLogStatsSummarySchema, DbLogStatsTimeSeriesPointSchema, dbLogStats, } from "./stats.js";
export { dbQuery, QueryColumnSchema, QueryResponseSchema, QueryResultSchema, } from "./query.js";
export { dbTables, generateCreateTableSQL, TableColumnSchema, TableSchemaSchema, TablesResponseSchema, } from "./tables.js";
export { DbExecuteQueryRequestSchema } from "./types.js";
export { DbInvalidArgumentError, DbResponseError } from "./util.js";
import { APIClient } from '@agentuity/api';
import { getServiceUrls } from '@agentuity/config';
import { createMinimalLogger, isLogger, resolveApiKey, resolveRegion, resolveServiceUrl, } from '@agentuity/client';
import { z } from 'zod';
import { dbQuery } from "./query.js";
import { dbTables } from "./tables.js";
import { dbLogs } from "./logs.js";
import { dbLogStats } from "./stats.js";
export const DBClientOptionsSchema = z.object({
    apiKey: z.string().optional().describe('API key for authentication'),
    url: z.string().optional().describe('Base URL for the DB API'),
    database: z.string().describe('Database name'),
    orgId: z.string().describe('Organization ID'),
    region: z.string().optional().describe('Cloud region'),
    logger: z.custom(isLogger).optional().describe('Custom logger instance'),
});
export class DBClient {
    #client;
    #database;
    #orgId;
    #region;
    constructor(options) {
        if (!options.database) {
            throw new Error('database is required for DBClient');
        }
        if (!options.orgId) {
            throw new Error('orgId is required for DBClient');
        }
        const apiKey = resolveApiKey(options.apiKey);
        const region = options.region || resolveRegion();
        const serviceUrls = getServiceUrls(region);
        const url = resolveServiceUrl({
            url: options.url,
            envKey: 'AGENTUITY_DB_URL',
            fallback: serviceUrls.catalyst,
        });
        const logger = options.logger ?? createMinimalLogger();
        this.#client = new APIClient(url, logger, apiKey ?? '');
        this.#database = options.database;
        this.#orgId = options.orgId;
        this.#region = region;
    }
    async query(sql) {
        return dbQuery(this.#client, {
            database: this.#database,
            query: sql,
            orgId: this.#orgId,
            region: this.#region,
        });
    }
    async tables() {
        return dbTables(this.#client, {
            database: this.#database,
            orgId: this.#orgId,
            region: this.#region,
        });
    }
    async logs(params) {
        return dbLogs(this.#client, {
            database: this.#database,
            orgId: this.#orgId,
            region: this.#region,
            ...params,
        });
    }
    async stats(params) {
        return dbLogStats(this.#client, {
            database: this.#database,
            orgId: this.#orgId,
            region: this.#region,
            ...params,
        });
    }
}
//# sourceMappingURL=index.js.map