/* eslint-disable */
// This code is autogenerated using @harnessio/oats-cli.
// Please do not modify this code directly.
import { useMutation, UseMutationOptions } from '@tanstack/react-query';

import type { ResponseMessageResponse } from '../schemas/ResponseMessageResponse';
import type { ResponseErrOldPassword } from '../schemas/ResponseErrOldPassword';
import type { ResponseErrInvalidCredentials } from '../schemas/ResponseErrInvalidCredentials';
import { fetcher, FetcherOptions } from 'services/fetcher';

export type UpdatePasswordRequestBody = {
  newPassword: string;
  oldPassword: string;
  username: string;
};

export type UpdatePasswordOkResponse = ResponseMessageResponse;

export type UpdatePasswordErrorResponse = ResponseErrOldPassword | ResponseErrInvalidCredentials;

export interface UpdatePasswordProps extends Omit<FetcherOptions<unknown, UpdatePasswordRequestBody>, 'url'> {
  body: UpdatePasswordRequestBody;
}

export function updatePassword(props: UpdatePasswordProps): Promise<UpdatePasswordOkResponse> {
  return fetcher<UpdatePasswordOkResponse, unknown, UpdatePasswordRequestBody>({
    url: `/auth/update/password`,
    method: 'POST',
    ...props
  });
}

export type UpdatePasswordMutationProps<T extends keyof UpdatePasswordProps> = Omit<UpdatePasswordProps, T> &
  Partial<Pick<UpdatePasswordProps, T>>;

/**
 * This API is used to update the password
 */
export function useUpdatePasswordMutation<T extends keyof UpdatePasswordProps>(
  props: Pick<Partial<UpdatePasswordProps>, T>,
  options?: Omit<
    UseMutationOptions<UpdatePasswordOkResponse, UpdatePasswordErrorResponse, UpdatePasswordMutationProps<T>>,
    'mutationKey' | 'mutationFn'
  >
) {
  return useMutation<UpdatePasswordOkResponse, UpdatePasswordErrorResponse, UpdatePasswordMutationProps<T>>(
    (mutateProps: UpdatePasswordMutationProps<T>) =>
      updatePassword({ ...props, ...mutateProps } as UpdatePasswordProps),
    options
  );
}
