import { z } from 'zod'

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

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

export type TTagSchema = z.infer<typeof tagSchema>

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