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

import { queryOptions, type UseMutationOptions } from "@tanstack/react-query";
import type { AxiosError } from "axios";
import { client as _heyApiClient } from "../client.gen";
import {
    createBoard,
    createProject,
    createStatus,
    deleteBoard,
    deleteProject,
    deleteStatus,
    getBoards,
    getDeals,
    getProjects,
    getStatuses,
    updateBoard,
    updateDeal,
    updateProject,
    updateStatus,
    type Options,
} from "../sdk.gen";
import type {
    CreateBoardData,
    CreateBoardError,
    CreateBoardResponse2,
    CreateProjectData,
    CreateProjectError,
    CreateProjectResponse2,
    CreateStatusData,
    CreateStatusError,
    CreateStatusResponse2,
    DeleteBoardData,
    DeleteBoardError,
    DeleteBoardResponse2,
    DeleteProjectData,
    DeleteProjectError,
    DeleteProjectResponse2,
    DeleteStatusData,
    DeleteStatusError,
    DeleteStatusResponse2,
    GetBoardsData,
    GetDealsData,
    GetProjectsData,
    GetStatusesData,
    UpdateBoardData,
    UpdateBoardError,
    UpdateBoardResponse2,
    UpdateDealData,
    UpdateDealError,
    UpdateDealResponse2,
    UpdateProjectData,
    UpdateProjectError,
    UpdateProjectResponse2,
    UpdateStatusData,
    UpdateStatusError,
    UpdateStatusResponse2,
} from "../types.gen";

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

const createQueryKey = <TOptions extends Options>(
    id: string,
    options?: TOptions,
    infinite?: boolean
): [QueryKey<TOptions>[0]] => {
    const params: QueryKey<TOptions>[0] = {
        _id: id,
        baseURL:
            options?.baseURL ||
            (options?.client ?? _heyApiClient).getConfig().baseURL,
    } as QueryKey<TOptions>[0];
    if (infinite) {
        params._infinite = infinite;
    }
    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 getBoardsQueryKey = (options: Options<GetBoardsData>) =>
    createQueryKey("getBoards", options);

/**
 * Get Boards
 */
export const getBoardsOptions = (options: Options<GetBoardsData>) => {
    return queryOptions({
        queryFn: async ({ queryKey, signal }) => {
            const { data } = await getBoards({
                ...options,
                ...queryKey[0],
                signal,
                throwOnError: true,
            });
            return data;
        },
        queryKey: getBoardsQueryKey(options),
    });
};

export const createBoardQueryKey = (options: Options<CreateBoardData>) =>
    createQueryKey("createBoard", options);

/**
 * Create Board
 */
export const createBoardOptions = (options: Options<CreateBoardData>) => {
    return queryOptions({
        queryFn: async ({ queryKey, signal }) => {
            const { data } = await createBoard({
                ...options,
                ...queryKey[0],
                signal,
                throwOnError: true,
            });
            return data;
        },
        queryKey: createBoardQueryKey(options),
    });
};

/**
 * Create Board
 */
export const createBoardMutation = (
    options?: Partial<Options<CreateBoardData>>
): UseMutationOptions<
    CreateBoardResponse2,
    AxiosError<CreateBoardError>,
    Options<CreateBoardData>
> => {
    const mutationOptions: UseMutationOptions<
        CreateBoardResponse2,
        AxiosError<CreateBoardError>,
        Options<CreateBoardData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await createBoard({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

/**
 * Delete Board
 */
export const deleteBoardMutation = (
    options?: Partial<Options<DeleteBoardData>>
): UseMutationOptions<
    DeleteBoardResponse2,
    AxiosError<DeleteBoardError>,
    Options<DeleteBoardData>
> => {
    const mutationOptions: UseMutationOptions<
        DeleteBoardResponse2,
        AxiosError<DeleteBoardError>,
        Options<DeleteBoardData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await deleteBoard({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

/**
 * Update Board
 */
export const updateBoardMutation = (
    options?: Partial<Options<UpdateBoardData>>
): UseMutationOptions<
    UpdateBoardResponse2,
    AxiosError<UpdateBoardError>,
    Options<UpdateBoardData>
> => {
    const mutationOptions: UseMutationOptions<
        UpdateBoardResponse2,
        AxiosError<UpdateBoardError>,
        Options<UpdateBoardData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await updateBoard({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

export const getDealsQueryKey = (options: Options<GetDealsData>) =>
    createQueryKey("getDeals", options);

/**
 * Get Deals
 */
export const getDealsOptions = (options: Options<GetDealsData>) => {
    return queryOptions({
        queryFn: async ({ queryKey, signal }) => {
            const { data } = await getDeals({
                ...options,
                ...queryKey[0],
                signal,
                throwOnError: true,
            });
            return data;
        },
        queryKey: getDealsQueryKey(options),
    });
};

/**
 * Update Deal
 */
export const updateDealMutation = (
    options?: Partial<Options<UpdateDealData>>
): UseMutationOptions<
    UpdateDealResponse2,
    AxiosError<UpdateDealError>,
    Options<UpdateDealData>
> => {
    const mutationOptions: UseMutationOptions<
        UpdateDealResponse2,
        AxiosError<UpdateDealError>,
        Options<UpdateDealData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await updateDeal({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

export const getProjectsQueryKey = (options?: Options<GetProjectsData>) =>
    createQueryKey("getProjects", options);

/**
 * Get Projects
 */
export const getProjectsOptions = (options?: Options<GetProjectsData>) => {
    return queryOptions({
        queryFn: async ({ queryKey, signal }) => {
            const { data } = await getProjects({
                ...options,
                ...queryKey[0],
                signal,
                throwOnError: true,
            });
            return data;
        },
        queryKey: getProjectsQueryKey(options),
    });
};

export const createProjectQueryKey = (options: Options<CreateProjectData>) =>
    createQueryKey("createProject", options);

/**
 * Create Project
 */
export const createProjectOptions = (options: Options<CreateProjectData>) => {
    return queryOptions({
        queryFn: async ({ queryKey, signal }) => {
            const { data } = await createProject({
                ...options,
                ...queryKey[0],
                signal,
                throwOnError: true,
            });
            return data;
        },
        queryKey: createProjectQueryKey(options),
    });
};

/**
 * Create Project
 */
export const createProjectMutation = (
    options?: Partial<Options<CreateProjectData>>
): UseMutationOptions<
    CreateProjectResponse2,
    AxiosError<CreateProjectError>,
    Options<CreateProjectData>
> => {
    const mutationOptions: UseMutationOptions<
        CreateProjectResponse2,
        AxiosError<CreateProjectError>,
        Options<CreateProjectData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await createProject({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

/**
 * Delete Project
 */
export const deleteProjectMutation = (
    options?: Partial<Options<DeleteProjectData>>
): UseMutationOptions<
    DeleteProjectResponse2,
    AxiosError<DeleteProjectError>,
    Options<DeleteProjectData>
> => {
    const mutationOptions: UseMutationOptions<
        DeleteProjectResponse2,
        AxiosError<DeleteProjectError>,
        Options<DeleteProjectData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await deleteProject({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

/**
 * Update Project
 */
export const updateProjectMutation = (
    options?: Partial<Options<UpdateProjectData>>
): UseMutationOptions<
    UpdateProjectResponse2,
    AxiosError<UpdateProjectError>,
    Options<UpdateProjectData>
> => {
    const mutationOptions: UseMutationOptions<
        UpdateProjectResponse2,
        AxiosError<UpdateProjectError>,
        Options<UpdateProjectData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await updateProject({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

export const getStatusesQueryKey = (options: Options<GetStatusesData>) =>
    createQueryKey("getStatuses", options);

/**
 * Get Statuses
 */
export const getStatusesOptions = (options: Options<GetStatusesData>) => {
    return queryOptions({
        queryFn: async ({ queryKey, signal }) => {
            const { data } = await getStatuses({
                ...options,
                ...queryKey[0],
                signal,
                throwOnError: true,
            });
            return data;
        },
        queryKey: getStatusesQueryKey(options),
    });
};

export const createStatusQueryKey = (options: Options<CreateStatusData>) =>
    createQueryKey("createStatus", options);

/**
 * Create Status
 */
export const createStatusOptions = (options: Options<CreateStatusData>) => {
    return queryOptions({
        queryFn: async ({ queryKey, signal }) => {
            const { data } = await createStatus({
                ...options,
                ...queryKey[0],
                signal,
                throwOnError: true,
            });
            return data;
        },
        queryKey: createStatusQueryKey(options),
    });
};

/**
 * Create Status
 */
export const createStatusMutation = (
    options?: Partial<Options<CreateStatusData>>
): UseMutationOptions<
    CreateStatusResponse2,
    AxiosError<CreateStatusError>,
    Options<CreateStatusData>
> => {
    const mutationOptions: UseMutationOptions<
        CreateStatusResponse2,
        AxiosError<CreateStatusError>,
        Options<CreateStatusData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await createStatus({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

/**
 * Delete Status
 */
export const deleteStatusMutation = (
    options?: Partial<Options<DeleteStatusData>>
): UseMutationOptions<
    DeleteStatusResponse2,
    AxiosError<DeleteStatusError>,
    Options<DeleteStatusData>
> => {
    const mutationOptions: UseMutationOptions<
        DeleteStatusResponse2,
        AxiosError<DeleteStatusError>,
        Options<DeleteStatusData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await deleteStatus({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};

/**
 * Update Status
 */
export const updateStatusMutation = (
    options?: Partial<Options<UpdateStatusData>>
): UseMutationOptions<
    UpdateStatusResponse2,
    AxiosError<UpdateStatusError>,
    Options<UpdateStatusData>
> => {
    const mutationOptions: UseMutationOptions<
        UpdateStatusResponse2,
        AxiosError<UpdateStatusError>,
        Options<UpdateStatusData>
    > = {
        mutationFn: async localOptions => {
            const { data } = await updateStatus({
                ...options,
                ...localOptions,
                throwOnError: true,
            });
            return data;
        },
    };
    return mutationOptions;
};
