import { getRootLogger } from '../utils/logger.js';
export class BaseConnector {
    log;
    config = null;
    auth;
    constructor() {
        this.log = getRootLogger().child({ component: this.constructor.name });
    }
    toDefinition() {
        return {
            id: this.id,
            name: this.name,
            description: this.description,
            connectionType: this.connectionType,
            configSchema: this.configSchema,
            methods: this.methods,
        };
    }
    findMethod(methodName) {
        return this.methods.find((m) => m.name === methodName);
    }
    requireMethod(methodName) {
        const method = this.findMethod(methodName);
        if (!method) {
            throw new Error(`Method "${methodName}" not found on connector "${this.id}". ` +
                `Available: ${this.methods.map((m) => m.name).join(', ')}`);
        }
        return method;
    }
    validateInput(method, input) {
        const result = method.inputSchema.safeParse(input);
        if (!result.success) {
            const errors = result.error.issues.map((i) => `${i.path.join('.')}: ${i.message}`).join('; ');
            throw new Error(`Invalid input for method "${method.name}": ${errors}`);
        }
        return result.data;
    }
    measureExecution(fn) {
        const start = performance.now();
        return fn().then((result) => ({
            result,
            durationMs: Math.round(performance.now() - start),
        }));
    }
}
//# sourceMappingURL=BaseConnector.js.map