import { Fetcher, FetchUtils, FetchOptions } from '@tableau/taco-toolkit/handlers'

export default class DataFetcher extends Fetcher {
  // PLACEHOLDER: the urls are NOT real endpoints. They are only for placeholder purpose.
  // Replace them with actual endpoints for corresponding file types.
  // Note: the permission setting in connector.json also needs to be updated accordingly.
  urls: Record<string, string> = {
    csv: 'https://www.example.com/user.csv',
    excel: 'https://www.example.com/user.xslx',
  } as const

  async *fetch({ handlerInput }: FetchOptions) {
    const { fileType } = handlerInput.data
    const url = this.urls[fileType]

    yield await FetchUtils.fetchArrayBuffer(url)
  }
}
