import { buildOAuthFlow, buildOAuthPromptText } from '../engine/oauth/config-guard.js';
import { listOAuthTokens } from '../storage/oauth-store.js';
import { z } from 'zod';
// ---------------------------------------------------------------------------
// Zod schemas (exported for register file)
// ---------------------------------------------------------------------------
export const StartOAuthFlowInputSchema = {
    projectPath: z.string().describe('Ruta absoluta del proyecto'),
    integration: z
        .enum(['figma', 'github', 'sentry', 'supabase'])
        .describe('Integración a autorizar. Valores: figma=Figma OAuth, github=GitHub OAuth, sentry=Sentry token guiado, supabase=Supabase service key guiada'),
};
export const OAuthStatusInputSchema = {
    projectPath: z.string().describe('Ruta absoluta del proyecto'),
};
// ---------------------------------------------------------------------------
// start_oauth_flow
// ---------------------------------------------------------------------------
export async function handleStartOAuthFlow(input) {
    const result = await buildOAuthFlow(input.integration, input.projectPath);
    const promptText = buildOAuthPromptText(result);
    return { content: [{ type: 'text', text: promptText }] };
}
// ---------------------------------------------------------------------------
// oauth_status
// ---------------------------------------------------------------------------
export async function handleOAuthStatus(input) {
    const tokens = await listOAuthTokens(input.projectPath);
    if (tokens.length === 0) {
        return {
            content: [{ type: 'text', text: 'No hay integraciones conectadas todavía.' }],
        };
    }
    const lines = ['**Integraciones OAuth autorizadas**', ''];
    for (const token of tokens) {
        const expiry = token.expiresAt ? ` (expira: ${token.expiresAt})` : '';
        lines.push(`- **${token.integration}** — conectado el ${token.storedAt}${expiry}`);
    }
    return { content: [{ type: 'text', text: lines.join('\n') }] };
}
//# sourceMappingURL=oauth-handler.js.map