import { useMutation } from '@tanstack/react-query'
import { useNavigate } from 'react-router'
import { authService } from '../services/authService'
import type { UserRole } from '../domain/enums'

export function useLogin() {
  const navigate = useNavigate()
  return useMutation({
    mutationFn: ({ email, password }: { email: string; password: string }) =>
      authService.login(email, password),
    onSuccess: () => {
      navigate('/')
    },
  })
}

export function useSwitchDemoRole() {
  const navigate = useNavigate()
  return useMutation({
    mutationFn: (role: UserRole) => authService.switchDemoRole(role),
    onSuccess: () => {
      navigate('/')
    },
  })
}

export function useSwitchOrganization() {
  return useMutation({
    mutationFn: (organizationId: string) => authService.switchOrganization(organizationId),
  })
}
