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

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

import { client } from '../client.gen';
import { getPrivateModels, type Options, postChatCompletions } from '../sdk.gen';
import type { GetPrivateModelsData, GetPrivateModelsResponse, PostChatCompletionsData, PostChatCompletionsResponse } from '../types.gen';

export const postChatCompletionsMutation = (options?: Partial<Options<PostChatCompletionsData>>): MutationOptions<PostChatCompletionsResponse, DefaultError, Options<PostChatCompletionsData>> => {
    const mutationOptions: MutationOptions<PostChatCompletionsResponse, DefaultError, Options<PostChatCompletionsData>> = {
        mutationFn: async (fnOptions) => {
            const { data } = await postChatCompletions({
                ...options,
                ...fnOptions,
                throwOnError: true
            });
            return data;
        }
    };
    return mutationOptions;
};

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 getPrivateModelsQueryKey = (options?: Options<GetPrivateModelsData>) => createQueryKey('getPrivateModels', options);

export const getPrivateModelsOptions = (options?: Options<GetPrivateModelsData>) => queryOptions<GetPrivateModelsResponse, DefaultError, GetPrivateModelsResponse, ReturnType<typeof getPrivateModelsQueryKey>>({
    queryFn: async ({ queryKey, signal }) => {
        const { data } = await getPrivateModels({
            ...options,
            ...queryKey[0],
            signal,
            throwOnError: true
        });
        return data;
    },
    queryKey: getPrivateModelsQueryKey(options)
});
