import { protectedProcedure, publicProcedure, router } from "@/server/trpc"

import { allLevels } from "./temp"

function fakingRequest<T>(payload: T): Promise<T> {
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve(payload)
    }, 1500)
  })
}

export const lotaltyQueryRouter = router({
  levels: router({
    all: publicProcedure.query(async function ({ ctx }) {
      // TODO: Make request to get user data from Scandic API
      return await fakingRequest<typeof allLevels>(allLevels)
    }),
    current: protectedProcedure.query(async function (opts) {
      // TODO: Make request to get user data from Scandic API
      return await fakingRequest<(typeof allLevels)[number]>(allLevels[1])
    }),
    next: protectedProcedure.query(async function (opts) {
      // TODO: Make request to get user data from Scandic API
      return await fakingRequest<(typeof allLevels)[number]>(allLevels[2])
    }),
  }),
})
