import { trpc } from '@/src/trpc-client'
import { LoginCredentials, RegisterData, UpdateProfileData } from '@/src/types/auth'

// API response types
interface RegisterResponse {
  token: string;
  user: {
    id: number;
    name?: string | null;
    email: string | null;
    mobile: string | null;
    profileImage?: string | null;
    createdAt: string;
  };
}

interface UpdateProfileResponse {
  token: string;
  user: {
    id: number;
    name?: string | null;
    email: string | null;
    mobile: string | null;
    profileImage?: string | null;
    bio?: string | null;
    dateOfBirth?: string | null;
    gender?: string | null;
    occupation?: string | null;
  };
}

// React Query hooks
export const useRegister = () => {
  const mutation = trpc.user.auth.register.useMutation()

  return {
    ...mutation,
    mutateAsync: async (data: RegisterData): Promise<RegisterResponse> => {
      const response = await mutation.mutateAsync(data)
      return response.data
    },
  }
};

export const useUpdateProfile = () => {
  const mutation = trpc.user.auth.updateProfile.useMutation()

  return {
    ...mutation,
    mutateAsync: async (data: UpdateProfileData): Promise<UpdateProfileResponse> => {
      const response = await mutation.mutateAsync(data)
      return response.data
    },
  }
};
