// engine/github/client.ts — Platform client factory and detection.
import { PlatformNotImplementedError, } from '../../types/github.js';
import { GitHubAdapter } from './adapters/github-adapter.js';
/**
 * Detect the git hosting platform from a remote URL.
 */
export function detectPlatform(remoteUrl) {
    if (/github\.com/i.test(remoteUrl)) {
        return 'github';
    }
    if (/gitlab\.com/i.test(remoteUrl) || /gitlab\./i.test(remoteUrl)) {
        return 'gitlab';
    }
    if (/bitbucket\.org/i.test(remoteUrl) || /bitbucket\./i.test(remoteUrl)) {
        return 'bitbucket';
    }
    return 'unknown';
}
/**
 * Factory function that creates the appropriate platform client.
 */
export function createPlatformClient(remoteUrl, exec) {
    const platform = detectPlatform(remoteUrl);
    switch (platform) {
        case 'github':
            return new GitHubAdapter(exec);
        case 'gitlab':
            throw new PlatformNotImplementedError('GitLab');
        case 'bitbucket':
            throw new PlatformNotImplementedError('Bitbucket');
        case 'unknown':
            throw new Error(`Could not detect git platform from remote URL: ${remoteUrl}. ` +
                `Supported platforms: GitHub, GitLab (planned), Bitbucket (planned).`);
    }
}
/**
 * Get the remote URL of the current git repository.
 */
export async function getRemoteUrl(exec) {
    try {
        const { stdout } = await exec('git', ['remote', 'get-url', 'origin']);
        return stdout.trim();
    }
    catch {
        throw new Error('Could not determine git remote URL. Make sure you are in a git repository with an "origin" remote.');
    }
}
/**
 * Get the current git branch name.
 */
export async function getCurrentBranch(exec) {
    const { stdout } = await exec('git', ['rev-parse', '--abbrev-ref', 'HEAD']);
    return stdout.trim();
}
//# sourceMappingURL=client.js.map