import { z } from 'zod'

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

const subscriptionSchema = z.object({
  data: z.array(
    z.object({
      id: z.string(),
      code: z.string(),
      name: z.string(),
    }),
  ),
})

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