import { z } from 'zod'

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

const userSchema = 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 type TUser = z.infer<typeof userSchema>

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