import { getGitStatus as apiGetGitStatus, getGitDiff as apiGetGitDiff, getGitBranch as apiGetGitBranch, stageFiles as apiStageFiles, unstageFiles as apiUnstageFiles, restoreFiles as apiRestoreFiles, deleteFiles as apiDeleteFiles, commitChanges as apiCommitChanges, generateCommitMessage as apiGenerateCommitMessage, pushCommits as apiPushCommits, pullChanges as apiPullChanges, initGitRepo as apiInitGitRepo, getGitRemotes as apiGetGitRemotes, addGitRemote as apiAddGitRemote, removeGitRemote as apiRemoveGitRemote, } from '@ottocode/api';
import { extractErrorMessage } from './utils';
export const gitMixin = {
    async initGitRepo() {
        const response = await apiInitGitRepo();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async getGitStatus() {
        const response = await apiGetGitStatus();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async getGitDiff(file, staged = false) {
        const response = await apiGetGitDiff({
            query: { file, staged: staged ? 'true' : 'false' },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async getGitDiffFullFile(file, staged = false) {
        const response = await apiGetGitDiff({
            query: {
                file,
                staged: staged ? 'true' : 'false',
                fullFile: 'true',
            },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async generateCommitMessage(sessionId) {
        const response = await apiGenerateCommitMessage({
            body: sessionId ? { sessionId } : {},
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async stageFiles(files) {
        const response = await apiStageFiles({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: { files },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async unstageFiles(files) {
        const response = await apiUnstageFiles({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: { files },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async restoreFiles(files) {
        const response = await apiRestoreFiles({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: { files },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async deleteFiles(files) {
        const response = await apiDeleteFiles({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: { files },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async commitChanges(message) {
        const response = await apiCommitChanges({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: { message },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async getGitBranch() {
        const response = await apiGetGitBranch();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async pushCommits() {
        const response = await apiPushCommits({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: {},
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async pullChanges() {
        const response = await apiPullChanges({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: {},
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async getRemotes() {
        const response = await apiGetGitRemotes();
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data?.remotes;
    },
    async addRemote(name, url) {
        const response = await apiAddGitRemote({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: { name, url },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
    async removeRemote(name) {
        const response = await apiRemoveGitRemote({
            // biome-ignore lint/suspicious/noExplicitAny: API type mismatch
            body: { name },
        });
        if (response.error)
            throw new Error(extractErrorMessage(response.error));
        // biome-ignore lint/suspicious/noExplicitAny: API response structure
        return response.data?.data;
    },
};
//# sourceMappingURL=git.js.map