/**
 * @ai-summary React Query hook for user signup
 */

import { useMutation } from '@tanstack/react-query';
import toast from 'react-hot-toast';
import { authApi } from '../api/auth.api';
import { SignupRequest } from '../types/auth.types';

interface ApiError {
  response?: {
    data?: {
      error?: string;
      message?: string;
    };
    status?: number;
  };
  message?: string;
}

export const useSignup = () => {
  return useMutation({
    mutationFn: (data: SignupRequest) => authApi.signup(data),
    onSuccess: () => {
      toast.success('Account created! Please check your email to verify your account.');
    },
    onError: (error: ApiError) => {
      const errorMessage = error.response?.data?.error || error.response?.data?.message || error.message || 'Failed to create account';
      toast.error(errorMessage);
    },
  });
};
