import { ErrorStatus, Result } from '@/lib/fetch/types'

export const fetchGoogleSheet = async (url: string) => {
  try {
    const res = await fetch(url, {
      method: 'GET',
      headers: {
        'Content-Type': 'application/json',
      },
    })

    switch (res.status) {
      case 200: return { data: await res.text() } as Result
      case 400: return { error: ErrorStatus.BAD_REQUEST } as Result
      case 404: return { error: ErrorStatus.NOT_FOUND } as Result
      case 500: return { error: ErrorStatus.INTERNAL_SERVER_ERROR } as Result
      default: return { error: ErrorStatus.INTERNAL_SERVER_ERROR } as Result
    }

  } catch (error) {
    console.error(error)
    return { error: ErrorStatus.INTERNAL_SERVER_ERROR } as Result
  }
}