
import { GetItemList } from '../../../@utility/data-structures/database'

import { storeTable } from '../variables'
import { createItemStore } from './create-item-store'

const getItemList: GetItemList = getItemListFunction

async function getItemListFunction (storeId: string): Promise<any[]> {
  if (!storeTable[storeId]) {
    await createItemStore(storeId)
  }

  const resultList: any[] = []

  await storeTable[storeId].iterate((value: any, _: string) => {
    resultList.push(value)
  })

  return resultList
}

export {
  getItemList
}