import { execSync, spawnSync } from 'node:child_process';
export class ClaudeAuthCliGateway {
    executor;
    spawnInteractive;
    constructor(deps = {}) {
        this.executor = deps.executeCommand ?? execSync;
        this.spawnInteractive =
            deps.spawnInteractive ??
                ((command, args) => {
                    const result = spawnSync(command, args, { stdio: 'inherit' });
                    return { status: result.status, signal: result.signal };
                });
    }
    async isLoggedIn() {
        try {
            this.executor('claude --version', { stdio: 'pipe' });
        }
        catch {
            return false;
        }
        try {
            const output = this.executor('claude /status', { stdio: 'pipe' });
            const text = output.toString().toLowerCase();
            return !text.includes('not logged in') && !text.includes('please login');
        }
        catch {
            return false;
        }
    }
    async triggerLogin() {
        const result = this.spawnInteractive('claude', ['/login']);
        if (result.status !== 0) {
            return { success: false, error: `claude /login exited with status ${result.status ?? 'null'}` };
        }
        return { success: true, error: null };
    }
}
//# sourceMappingURL=claudeAuth.cli.gateway.js.map