import { handleCreateBranch, handleCheckBranch, handleAutoSetup, handleWorktreeStart, handleWorktreeList, handleWorktreeCleanup, } from './git/branch-ops.js';
import { handleGeneratePr } from './git/pr-ops.js';
import { handleLinkCommits, handleStatus } from './git/commit-ops.js';
import { handleGenerateChangelog } from './git/changelog-ops.js';
import { handleSetupHooks } from './git/hook-ops.js';
import { handleSyncBranch, handleCheckGitflow, handleResolveConflict } from './git/sync-ops.js';
import { handleBreakingCheck } from './git/breaking-ops.js';
import { handleRelease, handleHotfix, handlePromote } from './git/release-ops.js';
import { handleCleanup } from './git/cleanup-ops.js';
import { importFromGitHubIssue, exportSpecToGitHubIssue, syncSpecWithGitHubIssue, } from './git/github-issues-ops.js';
export async function handleManageGit(params) {
    const { projectId, action, specId, config, files } = params;
    try {
        switch (action) {
            case 'create-branch':
                return await handleCreateBranch(projectId, specId, config);
            case 'generate-pr':
                return await handleGeneratePr(projectId, specId);
            case 'link-commits':
                return await handleLinkCommits(projectId, specId);
            case 'generate-changelog':
                return await handleGenerateChangelog(projectId, specId, config?.changelogFormat);
            case 'setup-hooks':
                return await handleSetupHooks(projectId, config);
            case 'check-branch':
                return await handleCheckBranch(projectId, specId, config);
            case 'status':
                return await handleStatus(projectId, specId);
            case 'sync-branch':
                return await handleSyncBranch(projectId, config);
            case 'check-gitflow':
                return await handleCheckGitflow(projectId, config);
            case 'resolve-conflict':
                return await handleResolveConflict(projectId, files);
            case 'breaking-check':
                return await handleBreakingCheck(projectId, config);
            case 'release':
                return await handleRelease(projectId, config);
            case 'hotfix':
                return await handleHotfix(projectId, config);
            case 'promote':
                return await handlePromote(projectId, config);
            case 'auto-setup':
                return await handleAutoSetup(projectId, specId, config);
            case 'cleanup':
                /* v8 ignore start */
                return await handleCleanup(projectId, config);
            /* v8 ignore stop */
            case 'import-issue':
                /* v8 ignore start */
                return await importFromGitHubIssue({
                    projectId,
                    issueNumber: config?.issueNumber ?? 0,
                    repo: config?.repo,
                });
            /* v8 ignore stop */
            case 'export-to-issue':
                /* v8 ignore start */
                return await exportSpecToGitHubIssue({
                    projectId,
                    specId: specId ?? '',
                    repo: config?.repo,
                });
            /* v8 ignore stop */
            case 'sync-issue':
                /* v8 ignore start */
                return await syncSpecWithGitHubIssue({
                    projectId,
                    specId: specId ?? '',
                    issueNumber: config?.issueNumber ?? 0,
                    repo: config?.repo,
                });
            /* v8 ignore stop */
            case 'worktree-start':
                return handleWorktreeStart(projectId, specId, config);
            case 'worktree-list':
                return await handleWorktreeList(projectId);
            case 'worktree-cleanup':
                return handleWorktreeCleanup(projectId, config);
            default:
                return {
                    content: [
                        {
                            type: 'text',
                            text: `Error: Unknown git action: ${String(action)}`,
                        },
                    ],
                    isError: true,
                };
        }
    }
    catch (err) {
        const message = err instanceof Error ? err.message : String(err);
        return {
            content: [{ type: 'text', text: `Error: ${message} (action: ${action})` }],
            isError: true,
        };
    }
}
//# sourceMappingURL=manage-git.js.map