import type { Manager } from './apiResponseTypes'
import { SITE_URL } from './utilities'

export async function fetchActiveManagers(): Promise<Manager[]> {
  return await fetchManagers(true)
}

export async function fetchRetiredManagers(): Promise<Manager[]> {
  return await fetchManagers(false)
}

async function fetchManagers(active: boolean): Promise<Manager[]> {
  const response = await fetch(`${SITE_URL}/api/v3/managers?active=${active}&short_output=true`)

  const managersResponse: {
    count: number
    managers: Manager[]
  } = await response.json()

  return managersResponse.managers
}
