"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getAccessToken = getAccessToken;
exports.listConnections = listConnections;
exports.revokeConnection = revokeConnection;
const oauth_1 = require("../../services/oauth");
/**
 * Get a fresh OAuth access token for an external service.
 * Automatically refreshes expired tokens.
 */
async function getAccessToken(args) {
    const token = await (0, oauth_1.getFreshAccessToken)(args.user_id, args.provider, args.label);
    return {
        access_token: token.accessToken,
        expires_at: token.expiresAt?.toISOString() ?? null,
        scopes: token.scopes,
        label: token.label,
    };
}
/**
 * List a user's connected OAuth providers.
 */
async function listConnections(args) {
    const connections = await (0, oauth_1.listOAuthConnections)(args.user_id);
    return { connections };
}
/**
 * Revoke an OAuth connection for a user.
 */
async function revokeConnection(args) {
    const deleted = await (0, oauth_1.deleteOAuthConnection)(args.user_id, args.provider, args.label);
    return { success: deleted };
}
