import axios from 'axios';

interface PullRequestOptions {
    title: string;
    body: string;
    branch: string;
}

export class GitHubClient {
    private token: string;
    private baseUrl: string = 'https://api.github.com';

    constructor(token: string) {
        this.token = token;
    }

    async createPullRequest(options: PullRequestOptions): Promise<string> {
        try {
            const response = await axios.post(
                `${this.baseUrl}/repos/${process.env.GITHUB_REPOSITORY}/pulls`,
                {
                    title: options.title,
                    body: options.body,
                    head: options.branch,
                    base: 'main'
                },
                {
                    headers: {
                        Authorization: `token ${this.token}`,
                        Accept: 'application/vnd.github.v3+json'
                    }
                }
            );
            return response.data.html_url;
        } catch (error) {
            console.error('Error creating PR:', error);
            throw error;
        }
    }
} 