/**
 * Generated by @openapi-codegen
 *
 * @version 0.0.1
 */
import * as reactQuery from '@tanstack/react-query';
import { useFirmwareToolContext, FirmwareToolContext } from './firmwareToolContext';
import type * as Fetcher from './firmwareToolFetcher';
import { firmwareToolFetch } from './firmwareToolFetcher';
import type * as Schemas from './firmwareToolSchemas';

export type GetIsCompatibleVersionPathParams = {
  version: string;
};

export type GetIsCompatibleVersionError = Fetcher.ErrorWrapper<undefined>;

export type GetIsCompatibleVersionVariables = {
  pathParams: GetIsCompatibleVersionPathParams;
} & FirmwareToolContext['fetcherOptions'];

/**
 * Is this api compatible with the server version given
 */
export const fetchGetIsCompatibleVersion = (
  variables: GetIsCompatibleVersionVariables,
  signal?: AbortSignal
) =>
  firmwareToolFetch<
    | {
        success: true;
      }
    | {
        success: false;
        reason: {
          message: string;
          versions: string;
        };
      },
    GetIsCompatibleVersionError,
    undefined,
    {},
    {},
    GetIsCompatibleVersionPathParams
  >({ url: '/is-compatible/{version}', method: 'get', ...variables, signal });

/**
 * Is this api compatible with the server version given
 */
export const useGetIsCompatibleVersion = <
  TData =
    | {
        success: true;
      }
    | {
        success: false;
        reason: {
          message: string;
          versions: string;
        };
      },
>(
  variables: GetIsCompatibleVersionVariables,
  options?: Omit<
    reactQuery.UseQueryOptions<
      | {
          success: true;
        }
      | {
          success: false;
          reason: {
            message: string;
            versions: string;
          };
        },
      GetIsCompatibleVersionError,
      TData
    >,
    'queryKey' | 'queryFn' | 'initialData'
  >
) => {
  const { fetcherOptions, queryOptions, queryKeyFn } = useFirmwareToolContext(options);
  return reactQuery.useQuery<
    | {
        success: true;
      }
    | {
        success: false;
        reason: {
          message: string;
          versions: string;
        };
      },
    GetIsCompatibleVersionError,
    TData
  >({
    queryKey: queryKeyFn({
      path: '/is-compatible/{version}',
      operationId: 'getIsCompatibleVersion',
      variables,
    }),
    queryFn: ({ signal }) =>
      fetchGetIsCompatibleVersion({ ...fetcherOptions, ...variables }, signal),
    ...options,
    ...queryOptions,
  });
};

export type GetHealthError = Fetcher.ErrorWrapper<undefined>;

export type GetHealthVariables = FirmwareToolContext['fetcherOptions'];

/**
 * Gives the status of the api
 * this endpoint will always return true
 */
export const fetchGetHealth = (variables: GetHealthVariables, signal?: AbortSignal) =>
  firmwareToolFetch<boolean, GetHealthError, undefined, {}, {}, {}>({
    url: '/health',
    method: 'get',
    ...variables,
    signal,
  });

/**
 * Gives the status of the api
 * this endpoint will always return true
 */
export const useGetHealth = <TData = boolean>(
  variables: GetHealthVariables,
  options?: Omit<
    reactQuery.UseQueryOptions<boolean, GetHealthError, TData>,
    'queryKey' | 'queryFn' | 'initialData'
  >
) => {
  const { fetcherOptions, queryOptions, queryKeyFn } = useFirmwareToolContext(options);
  return reactQuery.useQuery<boolean, GetHealthError, TData>({
    queryKey: queryKeyFn({
      path: '/health',
      operationId: 'getHealth',
      variables,
    }),
    queryFn: ({ signal }) =>
      fetchGetHealth({ ...fetcherOptions, ...variables }, signal),
    ...options,
    ...queryOptions,
  });
};

export type GetFirmwareSourcesError = Fetcher.ErrorWrapper<undefined>;

export type GetFirmwareSourcesResponse = Schemas.FirmwareSource[];

export type GetFirmwareSourcesVariables = FirmwareToolContext['fetcherOptions'];

/**
 * List all the sources you can build a firmware from
 */
export const fetchGetFirmwareSources = (
  variables: GetFirmwareSourcesVariables,
  signal?: AbortSignal
) =>
  firmwareToolFetch<
    GetFirmwareSourcesResponse,
    GetFirmwareSourcesError,
    undefined,
    {},
    {},
    {}
  >({ url: '/firmware/sources', method: 'get', ...variables, signal });

/**
 * List all the sources you can build a firmware from
 */
export const useGetFirmwareSources = <TData = GetFirmwareSourcesResponse>(
  variables: GetFirmwareSourcesVariables,
  options?: Omit<
    reactQuery.UseQueryOptions<
      GetFirmwareSourcesResponse,
      GetFirmwareSourcesError,
      TData
    >,
    'queryKey' | 'queryFn' | 'initialData'
  >
) => {
  const { fetcherOptions, queryOptions, queryKeyFn } = useFirmwareToolContext(options);
  return reactQuery.useQuery<
    GetFirmwareSourcesResponse,
    GetFirmwareSourcesError,
    TData
  >({
    queryKey: queryKeyFn({
      path: '/firmware/sources',
      operationId: 'getFirmwareSources',
      variables,
    }),
    queryFn: ({ signal }) =>
      fetchGetFirmwareSources({ ...fetcherOptions, ...variables }, signal),
    ...options,
    ...queryOptions,
  });
};

export type GetFirmwareBoardDefaultsQueryParams = {
  source: string;
  board: string;
  version: string;
};

export type GetFirmwareBoardDefaultsError = Fetcher.ErrorWrapper<undefined>;

export type GetFirmwareBoardDefaultsVariables = {
  queryParams: GetFirmwareBoardDefaultsQueryParams;
} & FirmwareToolContext['fetcherOptions'];

/**
 * Fet the defaults of a specific board on a specific firmware
 */
export const fetchGetFirmwareBoardDefaults = (
  variables: GetFirmwareBoardDefaultsVariables,
  signal?: AbortSignal
) =>
  firmwareToolFetch<
    Schemas.FirmwareBoardDefaultsNullable,
    GetFirmwareBoardDefaultsError,
    undefined,
    {},
    GetFirmwareBoardDefaultsQueryParams,
    {}
  >({ url: '/firmware/board-defaults', method: 'get', ...variables, signal });

/**
 * Fet the defaults of a specific board on a specific firmware
 */
export const useGetFirmwareBoardDefaults = <
  TData = Schemas.FirmwareBoardDefaultsNullable,
>(
  variables: GetFirmwareBoardDefaultsVariables,
  options?: Omit<
    reactQuery.UseQueryOptions<
      Schemas.FirmwareBoardDefaultsNullable,
      GetFirmwareBoardDefaultsError,
      TData
    >,
    'queryKey' | 'queryFn' | 'initialData'
  >
) => {
  const { fetcherOptions, queryOptions, queryKeyFn } = useFirmwareToolContext(options);
  return reactQuery.useQuery<
    Schemas.FirmwareBoardDefaultsNullable,
    GetFirmwareBoardDefaultsError,
    TData
  >({
    queryKey: queryKeyFn({
      path: '/firmware/board-defaults',
      operationId: 'getFirmwareBoardDefaults',
      variables,
    }),
    queryFn: ({ signal }) =>
      fetchGetFirmwareBoardDefaults({ ...fetcherOptions, ...variables }, signal),
    ...options,
    ...queryOptions,
  });
};

export type PostFirmwareBuildError = Fetcher.ErrorWrapper<undefined>;

export type PostFirmwareBuildVariables = {
  body: Schemas.BuildFirmwareBody;
} & FirmwareToolContext['fetcherOptions'];

export const fetchPostFirmwareBuild = (
  variables: PostFirmwareBuildVariables,
  signal?: AbortSignal
) =>
  firmwareToolFetch<
    Schemas.BuildStatusBasic | Schemas.BuildStatusDone,
    PostFirmwareBuildError,
    Schemas.BuildFirmwareBody,
    {},
    {},
    {}
  >({ url: '/firmware/build', method: 'post', ...variables, signal });

export const usePostFirmwareBuild = (
  options?: Omit<
    reactQuery.UseMutationOptions<
      Schemas.BuildStatusBasic | Schemas.BuildStatusDone,
      PostFirmwareBuildError,
      PostFirmwareBuildVariables
    >,
    'mutationFn'
  >
) => {
  const { fetcherOptions } = useFirmwareToolContext();
  return reactQuery.useMutation<
    Schemas.BuildStatusBasic | Schemas.BuildStatusDone,
    PostFirmwareBuildError,
    PostFirmwareBuildVariables
  >({
    mutationFn: (variables: PostFirmwareBuildVariables) =>
      fetchPostFirmwareBuild({ ...fetcherOptions, ...variables }),
    ...options,
  });
};

export type GetFirmwareIdPathParams = {
  id: string;
};

export type GetFirmwareIdError = Fetcher.ErrorWrapper<undefined>;

export type GetFirmwareIdVariables = {
  pathParams: GetFirmwareIdPathParams;
} & FirmwareToolContext['fetcherOptions'];

/**
 * Get the inforamtions about a firmware from its id
 * also provide more informations than the simple list, like pins and imus and files
 */
export const fetchGetFirmwareId = (
  variables: GetFirmwareIdVariables,
  signal?: AbortSignal
) =>
  firmwareToolFetch<
    Schemas.FirmwareWithFiles,
    GetFirmwareIdError,
    undefined,
    {},
    {},
    GetFirmwareIdPathParams
  >({ url: '/firmware/{id}', method: 'get', ...variables, signal });

/**
 * Get the inforamtions about a firmware from its id
 * also provide more informations than the simple list, like pins and imus and files
 */
export const useGetFirmwareId = <TData = Schemas.FirmwareWithFiles>(
  variables: GetFirmwareIdVariables,
  options?: Omit<
    reactQuery.UseQueryOptions<Schemas.FirmwareWithFiles, GetFirmwareIdError, TData>,
    'queryKey' | 'queryFn' | 'initialData'
  >
) => {
  const { fetcherOptions, queryOptions, queryKeyFn } = useFirmwareToolContext(options);
  return reactQuery.useQuery<Schemas.FirmwareWithFiles, GetFirmwareIdError, TData>({
    queryKey: queryKeyFn({
      path: '/firmware/{id}',
      operationId: 'getFirmwareId',
      variables,
    }),
    queryFn: ({ signal }) =>
      fetchGetFirmwareId({ ...fetcherOptions, ...variables }, signal),
    ...options,
    ...queryOptions,
  });
};

export type QueryOperation =
  | {
      path: '/is-compatible/{version}';
      operationId: 'getIsCompatibleVersion';
      variables: GetIsCompatibleVersionVariables;
    }
  | {
      path: '/health';
      operationId: 'getHealth';
      variables: GetHealthVariables;
    }
  | {
      path: '/firmware/sources';
      operationId: 'getFirmwareSources';
      variables: GetFirmwareSourcesVariables;
    }
  | {
      path: '/firmware/board-defaults';
      operationId: 'getFirmwareBoardDefaults';
      variables: GetFirmwareBoardDefaultsVariables;
    }
  | {
      path: '/firmware/{id}';
      operationId: 'getFirmwareId';
      variables: GetFirmwareIdVariables;
    };
