import { useQuery } from '@tanstack/react-query';
import { fetchDepartmentCollaboratorUsers } from '@/features/tickets/services/departmentSupportService';

export const departmentCollaboratorUsersQueryKey = (
  departmentId: string,
  search: string,
  excludeTicketId?: string,
) => ['departments', departmentId, 'collaborator-users', search, excludeTicketId ?? ''] as const;

export function useDepartmentCollaboratorUsers(
  departmentId: string | undefined,
  search: string,
  excludeTicketId?: string,
) {
  return useQuery({
    queryKey: departmentCollaboratorUsersQueryKey(departmentId ?? '', search, excludeTicketId),
    queryFn: () => fetchDepartmentCollaboratorUsers(departmentId!, search, excludeTicketId),
    enabled: Boolean(departmentId) && search.trim().length >= 1,
  });
}
