'use server';
import { resolve } from '../../lib/server-container.js';
import { GitHubAuthError, GitHubUrlParseError, GitHubCloneError, } from '../../../../../packages/core/src/application/ports/output/services/github-repository-service.interface.js';
export async function importGitHubRepository(input) {
    const { url, dest } = input;
    if (!url?.trim()) {
        return { error: 'GitHub URL is required' };
    }
    try {
        const useCase = resolve('ImportGitHubRepositoryUseCase');
        const repository = await useCase.execute({ url, dest });
        return { repository, forked: repository.isFork === true };
    }
    catch (error) {
        if (error instanceof GitHubAuthError) {
            return { error: 'GitHub CLI is not authenticated. Run `gh auth login` to sign in.' };
        }
        if (error instanceof GitHubUrlParseError) {
            return { error: `Invalid GitHub URL: ${error.message}` };
        }
        if (error instanceof GitHubCloneError) {
            return { error: `Clone failed: ${error.message}` };
        }
        const message = error instanceof Error ? error.message : 'Failed to import repository';
        return { error: message };
    }
}
