import { z } from 'zod'

import { HttpServer, type THttpServer } from '~/libs/http-server'

const playerSchema = z.object({
  data: z.object({
    id: z.string(),
    email: z.string(),
    subscribe_plan_code: z.string(),
    subscribe_plan_name: z.string(),
    subscribe_status: z.string(),
  }),
})

export const getUser = async (parameters: THttpServer) => {
  try {
    const { data } = await HttpServer(parameters).get(`/api/user/profile`)
    return playerSchema.parse(data)
  } catch (error) {
    // eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
    return Promise.reject(error)
  }
}
