// This file is auto-generated by @hey-api/openapi-ts

import { type DefaultError, type InfiniteData, infiniteQueryOptions, type MutationOptions, queryOptions } from '@tanstack/solid-query';

import { client } from '../client.gen';
import { acceptUpdateRequest, createOrgFolder, createSkill, createUpdateRequest, createUpdateRequestComment, createVersion, deleteCollaborator, deleteFile, deleteSkill, downloadSkill, downloadSkillFile, downloadSkillManifest, getAuthorIdentity, getDraft, getFile, getMergeState, getOrgFolder, getSkill, getSkillEditDocument, getUpdateRequest, getUpdateRequestDiff, getVersionManifest, githubStatus, listCollaborators, listFiles, listOrphanFolders, listSkills, listUpdateRequestComments, listUpdateRequests, listUsageEvents, listVersions, type Options, publisherRoot, purchaseSkill, putFile, reconcileOrphans, rejectUpdateRequest, replaceOrgFolder, resolveConflict, retryGithubPublish, skillMd, syncFromMain, transferOrgFolder, updateOrgFolder, updateSkill, updateSponsor, upsertAuthorIdentity, upsertCollaborator, usageSummary } from '../sdk.gen';
import type { AcceptUpdateRequestData, AcceptUpdateRequestResponse, CreateOrgFolderData, CreateOrgFolderResponse, CreateSkillData, CreateSkillResponse, CreateUpdateRequestCommentData, CreateUpdateRequestCommentResponse, CreateUpdateRequestData, CreateUpdateRequestResponse, CreateVersionData, CreateVersionResponse2, DeleteCollaboratorData, DeleteCollaboratorResponse, DeleteFileData, DeleteFileResponse, DeleteSkillData, DeleteSkillResponse, DownloadSkillData, DownloadSkillFileData, DownloadSkillFileResponse, DownloadSkillManifestData, DownloadSkillManifestResponse, DownloadSkillResponse, GetAuthorIdentityData, GetAuthorIdentityResponse, GetDraftData, GetDraftResponse, GetFileData, GetFileResponse2, GetMergeStateData, GetMergeStateResponse, GetOrgFolderData, GetOrgFolderResponse, GetSkillData, GetSkillEditDocumentData, GetSkillEditDocumentResponse, GetSkillResponse, GetUpdateRequestData, GetUpdateRequestDiffData, GetUpdateRequestDiffResponse, GetUpdateRequestResponse, GetVersionManifestData, GetVersionManifestResponse, GithubStatusData, GithubStatusResponse, ListCollaboratorsData, ListCollaboratorsResponse2, ListFilesData, ListFilesResponse2, ListOrphanFoldersData, ListOrphanFoldersResponse, ListSkillsData, ListSkillsResponse2, ListUpdateRequestCommentsData, ListUpdateRequestCommentsResponse2, ListUpdateRequestsData, ListUpdateRequestsResponse2, ListUsageEventsData, ListUsageEventsResponse2, ListVersionsData, ListVersionsResponse2, PublisherRootData, PublisherRootResponse, PurchaseSkillData, PurchaseSkillResponse, PutFileData, PutFileResponse, ReconcileOrphansData, ReconcileOrphansError, ReconcileOrphansResponse, RejectUpdateRequestData, RejectUpdateRequestResponse, ReplaceOrgFolderData, ReplaceOrgFolderResponse, ResolveConflictData, ResolveConflictResponse, RetryGithubPublishData, RetryGithubPublishResponse, SkillMdData, SyncFromMainData, SyncFromMainResponse, TransferOrgFolderData, TransferOrgFolderResponse, UpdateOrgFolderData, UpdateOrgFolderResponse, UpdateSkillData, UpdateSkillResponse, UpdateSponsorData, UpdateSponsorResponse, UpsertAuthorIdentityData, UpsertAuthorIdentityResponse, UpsertCollaboratorData, UpsertCollaboratorResponse, UsageSummaryData, UsageSummaryResponse2 } from '../types.gen';

export type QueryKey<TOptions extends Options> = [
    Pick<TOptions, 'baseUrl' | 'body' | 'headers' | 'path' | 'query'> & {
        _id: string;
        _infinite?: boolean;
        tags?: ReadonlyArray<string>;
    }
];

const createQueryKey = <TOptions extends Options>(id: string, options?: TOptions, infinite?: boolean, tags?: ReadonlyArray<string>): [
    QueryKey<TOptions>[0]
] => {
    const params: QueryKey<TOptions>[0] = { _id: id, baseUrl: options?.baseUrl || (options?.client ?? client).getConfig().baseUrl } as QueryKey<TOptions>[0];
    if (infinite) {
        params._infinite = infinite;
    }
    if (tags) {
        params.tags = tags;
    }
    if (options?.body) {
        params.body = options.body;
    }
    if (options?.headers) {
        params.headers = options.headers;
    }
    if (options?.path) {
        params.path = options.path;
    }
    if (options?.query) {
        params.query = options.query;
    }
    return [params];
};

export const publisherRootQueryKey = (options?: Options<PublisherRootData>) => createQueryKey('publisherRoot', options);

export const publisherRootOptions = (options?: Options<PublisherRootData>) => queryOptions<PublisherRootResponse, DefaultError, PublisherRootResponse, ReturnType<typeof publisherRootQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await publisherRoot({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: publisherRootQueryKey(options)
});

export const listOrphanFoldersQueryKey = (options?: Options<ListOrphanFoldersData>) => createQueryKey('listOrphanFolders', options);

/**
 * Operator inventory of canonical-repo paths the gateway has no
 * claim on.
 *
 * Authorization: any caller with `X-Seren-User-Role: admin` (platform
 * admin set by Seren Core's `ADMIN_USER_IDS`). The endpoint is
 * **read-only** and does not return per-org data — every orphan is by
 * definition a path the gateway has lost track of, so scoping it to one
 * organization would defeat the visibility purpose. Unauthorized callers
 * receive 403.
 *
 * On success returns:
 *
 * ```json
 * {
 * "head_commit_sha": "...",
 * "head_tree_sha": "...",
 * "orphan_folders": [
 * {
 * "folder_slug": "org-deadbeef",
 * "skill_folder_name": "grid-trader",
 * "paths": ["org-deadbeef/grid-trader/SKILL.md", "..."]
 * }
 * ]
 * }
 * ```
 *
 * Failure modes:
 *
 * - 403 if the caller lacks `X-Seren-User-Role=admin`.
 * - 400 if GitHub publishing is not configured for this deployment.
 * - 500 if GitHub returned a truncated tree listing (we cannot
 * trust a partial view for an inventory pass — same posture as
 * `derive_orphan_paths` in `github_status`).
 */
export const listOrphanFoldersOptions = (options?: Options<ListOrphanFoldersData>) => queryOptions<ListOrphanFoldersResponse, DefaultError, ListOrphanFoldersResponse, ReturnType<typeof listOrphanFoldersQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await listOrphanFolders({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listOrphanFoldersQueryKey(options)
});

export const getAuthorIdentityQueryKey = (options?: Options<GetAuthorIdentityData>) => createQueryKey('getAuthorIdentity', options);

export const getAuthorIdentityOptions = (options?: Options<GetAuthorIdentityData>) => queryOptions<GetAuthorIdentityResponse, DefaultError, GetAuthorIdentityResponse, ReturnType<typeof getAuthorIdentityQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getAuthorIdentity({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getAuthorIdentityQueryKey(options)
});

export const upsertAuthorIdentityMutation = (options?: Partial<Options<UpsertAuthorIdentityData>>): MutationOptions<UpsertAuthorIdentityResponse, DefaultError, Options<UpsertAuthorIdentityData>> => {
    const mutationOptions: MutationOptions<UpsertAuthorIdentityResponse, DefaultError, Options<UpsertAuthorIdentityData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await upsertAuthorIdentity({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const getOrgFolderQueryKey = (options: Options<GetOrgFolderData>) => createQueryKey('getOrgFolder', options);

export const getOrgFolderOptions = (options: Options<GetOrgFolderData>) => queryOptions<GetOrgFolderResponse, DefaultError, GetOrgFolderResponse, ReturnType<typeof getOrgFolderQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getOrgFolder({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getOrgFolderQueryKey(options)
});

export const updateOrgFolderMutation = (options?: Partial<Options<UpdateOrgFolderData>>): MutationOptions<UpdateOrgFolderResponse, DefaultError, Options<UpdateOrgFolderData>> => {
    const mutationOptions: MutationOptions<UpdateOrgFolderResponse, DefaultError, Options<UpdateOrgFolderData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await updateOrgFolder({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const createOrgFolderMutation = (options?: Partial<Options<CreateOrgFolderData>>): MutationOptions<CreateOrgFolderResponse, DefaultError, Options<CreateOrgFolderData>> => {
    const mutationOptions: MutationOptions<CreateOrgFolderResponse, DefaultError, Options<CreateOrgFolderData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await createOrgFolder({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const replaceOrgFolderMutation = (options?: Partial<Options<ReplaceOrgFolderData>>): MutationOptions<ReplaceOrgFolderResponse, DefaultError, Options<ReplaceOrgFolderData>> => {
    const mutationOptions: MutationOptions<ReplaceOrgFolderResponse, DefaultError, Options<ReplaceOrgFolderData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await replaceOrgFolder({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const transferOrgFolderMutation = (options?: Partial<Options<TransferOrgFolderData>>): MutationOptions<TransferOrgFolderResponse, DefaultError, Options<TransferOrgFolderData>> => {
    const mutationOptions: MutationOptions<TransferOrgFolderResponse, DefaultError, Options<TransferOrgFolderData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await transferOrgFolder({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const skillMdQueryKey = (options?: Options<SkillMdData>) => createQueryKey('skillMd', options);

export const skillMdOptions = (options?: Options<SkillMdData>) => queryOptions<unknown, DefaultError, unknown, ReturnType<typeof skillMdQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await skillMd({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: skillMdQueryKey(options)
});

export const listSkillsQueryKey = (options?: Options<ListSkillsData>) => createQueryKey('listSkills', options);

export const listSkillsOptions = (options?: Options<ListSkillsData>) => queryOptions<ListSkillsResponse2, DefaultError, ListSkillsResponse2, ReturnType<typeof listSkillsQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await listSkills({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listSkillsQueryKey(options)
});

const createInfiniteParams = <K extends Pick<QueryKey<Options>[0], 'body' | 'headers' | 'path' | 'query'>>(queryKey: QueryKey<Options>, page: K) => {
    const params = { ...queryKey[0] };
    if (page.body) {
        params.body = {
            ...queryKey[0].body as any,
            ...page.body as any
        };
    }
    if (page.headers) {
        params.headers = {
            ...queryKey[0].headers,
            ...page.headers
        };
    }
    if (page.path) {
        params.path = {
            ...queryKey[0].path as any,
            ...page.path as any
        };
    }
    if (page.query) {
        params.query = {
            ...queryKey[0].query as any,
            ...page.query as any
        };
    }
    return params as unknown as typeof page;
};

export const listSkillsInfiniteQueryKey = (options?: Options<ListSkillsData>): QueryKey<Options<ListSkillsData>> => createQueryKey('listSkills', options, true);

export const listSkillsInfiniteOptions = (options?: Options<ListSkillsData>) => infiniteQueryOptions<ListSkillsResponse2, DefaultError, InfiniteData<ListSkillsResponse2>, QueryKey<Options<ListSkillsData>>, number | null | Pick<QueryKey<Options<ListSkillsData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
    queryFn: async ({ pageParam, queryKey, signal }) => {
        // @ts-ignore
        const page: Pick<QueryKey<Options<ListSkillsData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : {
            query: {
                offset: pageParam
            }
        };
        const params = createInfiniteParams(queryKey, page);
        const { data } = await listSkills({
            ...options,
            ...params,
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listSkillsInfiniteQueryKey(options)
});

export const createSkillMutation = (options?: Partial<Options<CreateSkillData>>): MutationOptions<CreateSkillResponse, DefaultError, Options<CreateSkillData>> => {
    const mutationOptions: MutationOptions<CreateSkillResponse, DefaultError, Options<CreateSkillData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await createSkill({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const deleteSkillMutation = (options?: Partial<Options<DeleteSkillData>>): MutationOptions<DeleteSkillResponse, DefaultError, Options<DeleteSkillData>> => {
    const mutationOptions: MutationOptions<DeleteSkillResponse, DefaultError, Options<DeleteSkillData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await deleteSkill({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const getSkillQueryKey = (options: Options<GetSkillData>) => createQueryKey('getSkill', options);

export const getSkillOptions = (options: Options<GetSkillData>) => queryOptions<GetSkillResponse, DefaultError, GetSkillResponse, ReturnType<typeof getSkillQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getSkill({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getSkillQueryKey(options)
});

export const updateSkillMutation = (options?: Partial<Options<UpdateSkillData>>): MutationOptions<UpdateSkillResponse, DefaultError, Options<UpdateSkillData>> => {
    const mutationOptions: MutationOptions<UpdateSkillResponse, DefaultError, Options<UpdateSkillData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await updateSkill({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const listCollaboratorsQueryKey = (options: Options<ListCollaboratorsData>) => createQueryKey('listCollaborators', options);

export const listCollaboratorsOptions = (options: Options<ListCollaboratorsData>) => queryOptions<ListCollaboratorsResponse2, DefaultError, ListCollaboratorsResponse2, ReturnType<typeof listCollaboratorsQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await listCollaborators({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listCollaboratorsQueryKey(options)
});

export const deleteCollaboratorMutation = (options?: Partial<Options<DeleteCollaboratorData>>): MutationOptions<DeleteCollaboratorResponse, DefaultError, Options<DeleteCollaboratorData>> => {
    const mutationOptions: MutationOptions<DeleteCollaboratorResponse, DefaultError, Options<DeleteCollaboratorData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await deleteCollaborator({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const upsertCollaboratorMutation = (options?: Partial<Options<UpsertCollaboratorData>>): MutationOptions<UpsertCollaboratorResponse, DefaultError, Options<UpsertCollaboratorData>> => {
    const mutationOptions: MutationOptions<UpsertCollaboratorResponse, DefaultError, Options<UpsertCollaboratorData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await upsertCollaborator({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const downloadSkillQueryKey = (options: Options<DownloadSkillData>) => createQueryKey('downloadSkill', options);

export const downloadSkillOptions = (options: Options<DownloadSkillData>) => queryOptions<DownloadSkillResponse, DefaultError, DownloadSkillResponse, ReturnType<typeof downloadSkillQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await downloadSkill({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: downloadSkillQueryKey(options)
});

export const downloadSkillFileQueryKey = (options: Options<DownloadSkillFileData>) => createQueryKey('downloadSkillFile', options);

export const downloadSkillFileOptions = (options: Options<DownloadSkillFileData>) => queryOptions<DownloadSkillFileResponse, DefaultError, DownloadSkillFileResponse, ReturnType<typeof downloadSkillFileQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await downloadSkillFile({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: downloadSkillFileQueryKey(options)
});

export const downloadSkillManifestQueryKey = (options: Options<DownloadSkillManifestData>) => createQueryKey('downloadSkillManifest', options);

export const downloadSkillManifestOptions = (options: Options<DownloadSkillManifestData>) => queryOptions<DownloadSkillManifestResponse, DefaultError, DownloadSkillManifestResponse, ReturnType<typeof downloadSkillManifestQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await downloadSkillManifest({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: downloadSkillManifestQueryKey(options)
});

export const getDraftQueryKey = (options: Options<GetDraftData>) => createQueryKey('getDraft', options);

export const getDraftOptions = (options: Options<GetDraftData>) => queryOptions<GetDraftResponse, DefaultError, GetDraftResponse, ReturnType<typeof getDraftQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getDraft({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getDraftQueryKey(options)
});

export const getMergeStateQueryKey = (options: Options<GetMergeStateData>) => createQueryKey('getMergeState', options);

export const getMergeStateOptions = (options: Options<GetMergeStateData>) => queryOptions<GetMergeStateResponse, DefaultError, GetMergeStateResponse, ReturnType<typeof getMergeStateQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getMergeState({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getMergeStateQueryKey(options)
});

export const resolveConflictMutation = (options?: Partial<Options<ResolveConflictData>>): MutationOptions<ResolveConflictResponse, DefaultError, Options<ResolveConflictData>> => {
    const mutationOptions: MutationOptions<ResolveConflictResponse, DefaultError, Options<ResolveConflictData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await resolveConflict({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const getSkillEditDocumentQueryKey = (options: Options<GetSkillEditDocumentData>) => createQueryKey('getSkillEditDocument', options);

export const getSkillEditDocumentOptions = (options: Options<GetSkillEditDocumentData>) => queryOptions<GetSkillEditDocumentResponse, DefaultError, GetSkillEditDocumentResponse, ReturnType<typeof getSkillEditDocumentQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getSkillEditDocument({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getSkillEditDocumentQueryKey(options)
});

export const listFilesQueryKey = (options: Options<ListFilesData>) => createQueryKey('listFiles', options);

/**
 * `GET /skills/{slug}/files` -- list every file in the current
 * version's bundle, plus a synthetic `SKILL.md` entry.
 */
export const listFilesOptions = (options: Options<ListFilesData>) => queryOptions<ListFilesResponse2, DefaultError, ListFilesResponse2, ReturnType<typeof listFilesQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await listFiles({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listFilesQueryKey(options)
});

/**
 * `DELETE /skills/{slug}/files/{path...}` -- drop one file.
 */
export const deleteFileMutation = (options?: Partial<Options<DeleteFileData>>): MutationOptions<DeleteFileResponse, DefaultError, Options<DeleteFileData>> => {
    const mutationOptions: MutationOptions<DeleteFileResponse, DefaultError, Options<DeleteFileData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await deleteFile({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const getFileQueryKey = (options: Options<GetFileData>) => createQueryKey('getFile', options);

/**
 * `GET /skills/{slug}/files/{path...}` -- one file's bytes.
 */
export const getFileOptions = (options: Options<GetFileData>) => queryOptions<GetFileResponse2, DefaultError, GetFileResponse2, ReturnType<typeof getFileQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getFile({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getFileQueryKey(options)
});

/**
 * `PUT /skills/{slug}/files/{path...}` -- replace or add one file.
 */
export const putFileMutation = (options?: Partial<Options<PutFileData>>): MutationOptions<PutFileResponse, DefaultError, Options<PutFileData>> => {
    const mutationOptions: MutationOptions<PutFileResponse, DefaultError, Options<PutFileData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await putFile({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const githubStatusQueryKey = (options: Options<GithubStatusData>) => createQueryKey('githubStatus', options);

export const githubStatusOptions = (options: Options<GithubStatusData>) => queryOptions<GithubStatusResponse, DefaultError, GithubStatusResponse, ReturnType<typeof githubStatusQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await githubStatus({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: githubStatusQueryKey(options)
});

/**
 * `POST /skills/{slug}/github/reconcile-orphans` -- ops endpoint
 * that mechanically removes canonical-repo paths the gateway no
 * longer claims for this skill. Issue #22 acceptance:
 *
 * - Owner, org-admin, or platform-admin authz (same
 * `ensure_can_operate_skill_catalog` pattern as
 * `/github/sync-from-main` and `/github/retry`).
 * - `confirm: true` is required. `false` or missing returns 409.
 * - The handler re-derives the **live** orphan-path set against the
 * canonical-repo HEAD and returns 409 if it does not match the
 * `expected_orphan_paths` payload (optimistic concurrency mirrors
 * `expected_current_version_id`).
 * - On match (and `dry_run: false`): stages one signed commit on
 * the canonical branch deleting every path. Author/committer is
 * the forward-publish bot pair so reverse-sync skips the commit
 * via `is_forward_publish_commit`.
 * - On `dry_run: true`: skips the commit and returns the planned
 * shape (paths + parent commit SHA + audit row id) without
 * touching GitHub.
 * - Records a `skill_orphan_reconciliations` audit row in both
 * modes (issue #22 acceptance criterion + migration 011).
 */
export const reconcileOrphansMutation = (options?: Partial<Options<ReconcileOrphansData>>): MutationOptions<ReconcileOrphansResponse, ReconcileOrphansError, Options<ReconcileOrphansData>> => {
    const mutationOptions: MutationOptions<ReconcileOrphansResponse, ReconcileOrphansError, Options<ReconcileOrphansData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await reconcileOrphans({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const retryGithubPublishMutation = (options?: Partial<Options<RetryGithubPublishData>>): MutationOptions<RetryGithubPublishResponse, DefaultError, Options<RetryGithubPublishData>> => {
    const mutationOptions: MutationOptions<RetryGithubPublishResponse, DefaultError, Options<RetryGithubPublishData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await retryGithubPublish({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

/**
 * `POST /skills/{slug}/github/sync-from-main` -- ops endpoint that
 * re-fetches the canonical GitHub bundle at HEAD and reconciles it
 * into a new gateway version. No-op when the resulting
 * `content_hash_bundle` matches the current version. Requires owner,
 * org-admin, or `X-Seren-User-Role=admin`.
 */
export const syncFromMainMutation = (options?: Partial<Options<SyncFromMainData>>): MutationOptions<SyncFromMainResponse, DefaultError, Options<SyncFromMainData>> => {
    const mutationOptions: MutationOptions<SyncFromMainResponse, DefaultError, Options<SyncFromMainData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await syncFromMain({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const purchaseSkillMutation = (options?: Partial<Options<PurchaseSkillData>>): MutationOptions<PurchaseSkillResponse, DefaultError, Options<PurchaseSkillData>> => {
    const mutationOptions: MutationOptions<PurchaseSkillResponse, DefaultError, Options<PurchaseSkillData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await purchaseSkill({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const updateSponsorMutation = (options?: Partial<Options<UpdateSponsorData>>): MutationOptions<UpdateSponsorResponse, DefaultError, Options<UpdateSponsorData>> => {
    const mutationOptions: MutationOptions<UpdateSponsorResponse, DefaultError, Options<UpdateSponsorData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await updateSponsor({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const listUpdateRequestsQueryKey = (options: Options<ListUpdateRequestsData>) => createQueryKey('listUpdateRequests', options);

export const listUpdateRequestsOptions = (options: Options<ListUpdateRequestsData>) => queryOptions<ListUpdateRequestsResponse2, DefaultError, ListUpdateRequestsResponse2, ReturnType<typeof listUpdateRequestsQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await listUpdateRequests({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listUpdateRequestsQueryKey(options)
});

export const createUpdateRequestMutation = (options?: Partial<Options<CreateUpdateRequestData>>): MutationOptions<CreateUpdateRequestResponse, DefaultError, Options<CreateUpdateRequestData>> => {
    const mutationOptions: MutationOptions<CreateUpdateRequestResponse, DefaultError, Options<CreateUpdateRequestData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await createUpdateRequest({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const listVersionsQueryKey = (options: Options<ListVersionsData>) => createQueryKey('listVersions', options);

export const listVersionsOptions = (options: Options<ListVersionsData>) => queryOptions<ListVersionsResponse2, DefaultError, ListVersionsResponse2, ReturnType<typeof listVersionsQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await listVersions({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listVersionsQueryKey(options)
});

export const createVersionMutation = (options?: Partial<Options<CreateVersionData>>): MutationOptions<CreateVersionResponse2, DefaultError, Options<CreateVersionData>> => {
    const mutationOptions: MutationOptions<CreateVersionResponse2, DefaultError, Options<CreateVersionData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await createVersion({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const getVersionManifestQueryKey = (options: Options<GetVersionManifestData>) => createQueryKey('getVersionManifest', options);

export const getVersionManifestOptions = (options: Options<GetVersionManifestData>) => queryOptions<GetVersionManifestResponse, DefaultError, GetVersionManifestResponse, ReturnType<typeof getVersionManifestQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getVersionManifest({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getVersionManifestQueryKey(options)
});

export const getUpdateRequestQueryKey = (options: Options<GetUpdateRequestData>) => createQueryKey('getUpdateRequest', options);

export const getUpdateRequestOptions = (options: Options<GetUpdateRequestData>) => queryOptions<GetUpdateRequestResponse, DefaultError, GetUpdateRequestResponse, ReturnType<typeof getUpdateRequestQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getUpdateRequest({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getUpdateRequestQueryKey(options)
});

export const acceptUpdateRequestMutation = (options?: Partial<Options<AcceptUpdateRequestData>>): MutationOptions<AcceptUpdateRequestResponse, DefaultError, Options<AcceptUpdateRequestData>> => {
    const mutationOptions: MutationOptions<AcceptUpdateRequestResponse, DefaultError, Options<AcceptUpdateRequestData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await acceptUpdateRequest({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const listUpdateRequestCommentsQueryKey = (options: Options<ListUpdateRequestCommentsData>) => createQueryKey('listUpdateRequestComments', options);

export const listUpdateRequestCommentsOptions = (options: Options<ListUpdateRequestCommentsData>) => queryOptions<ListUpdateRequestCommentsResponse2, DefaultError, ListUpdateRequestCommentsResponse2, ReturnType<typeof listUpdateRequestCommentsQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await listUpdateRequestComments({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listUpdateRequestCommentsQueryKey(options)
});

export const createUpdateRequestCommentMutation = (options?: Partial<Options<CreateUpdateRequestCommentData>>): MutationOptions<CreateUpdateRequestCommentResponse, DefaultError, Options<CreateUpdateRequestCommentData>> => {
    const mutationOptions: MutationOptions<CreateUpdateRequestCommentResponse, DefaultError, Options<CreateUpdateRequestCommentData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await createUpdateRequestComment({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const getUpdateRequestDiffQueryKey = (options: Options<GetUpdateRequestDiffData>) => createQueryKey('getUpdateRequestDiff', options);

export const getUpdateRequestDiffOptions = (options: Options<GetUpdateRequestDiffData>) => queryOptions<GetUpdateRequestDiffResponse, DefaultError, GetUpdateRequestDiffResponse, ReturnType<typeof getUpdateRequestDiffQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getUpdateRequestDiff({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getUpdateRequestDiffQueryKey(options)
});

export const rejectUpdateRequestMutation = (options?: Partial<Options<RejectUpdateRequestData>>): MutationOptions<RejectUpdateRequestResponse, DefaultError, Options<RejectUpdateRequestData>> => {
    const mutationOptions: MutationOptions<RejectUpdateRequestResponse, DefaultError, Options<RejectUpdateRequestData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await rejectUpdateRequest({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

export const listUsageEventsQueryKey = (options?: Options<ListUsageEventsData>) => createQueryKey('listUsageEvents', options);

export const listUsageEventsOptions = (options?: Options<ListUsageEventsData>) => queryOptions<ListUsageEventsResponse2, DefaultError, ListUsageEventsResponse2, ReturnType<typeof listUsageEventsQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await listUsageEvents({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listUsageEventsQueryKey(options)
});

export const listUsageEventsInfiniteQueryKey = (options?: Options<ListUsageEventsData>): QueryKey<Options<ListUsageEventsData>> => createQueryKey('listUsageEvents', options, true);

export const listUsageEventsInfiniteOptions = (options?: Options<ListUsageEventsData>) => infiniteQueryOptions<ListUsageEventsResponse2, DefaultError, InfiniteData<ListUsageEventsResponse2>, QueryKey<Options<ListUsageEventsData>>, number | null | Pick<QueryKey<Options<ListUsageEventsData>>[0], 'body' | 'headers' | 'path' | 'query'>>(
// @ts-ignore
{
    queryFn: async ({ pageParam, queryKey, signal }) => {
        // @ts-ignore
        const page: Pick<QueryKey<Options<ListUsageEventsData>>[0], 'body' | 'headers' | 'path' | 'query'> = typeof pageParam === 'object' ? pageParam : {
            query: {
                offset: pageParam
            }
        };
        const params = createInfiniteParams(queryKey, page);
        const { data } = await listUsageEvents({
            ...options,
            ...params,
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: listUsageEventsInfiniteQueryKey(options)
});

export const usageSummaryQueryKey = (options?: Options<UsageSummaryData>) => createQueryKey('usageSummary', options);

export const usageSummaryOptions = (options?: Options<UsageSummaryData>) => queryOptions<UsageSummaryResponse2, DefaultError, UsageSummaryResponse2, ReturnType<typeof usageSummaryQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await usageSummary({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: usageSummaryQueryKey(options)
});
