import { z } from 'zod'

import { HttpServer } from '~/libs/http-server'
import type { TLoginSchema } from '~/pages/staff-login'

const loginResponseSchema = z.object({
  data: z.object({
    token: z.string(),
  }),
})

export const staffLoginRequest = async (payload: TLoginSchema) => {
  try {
    const { data } = await HttpServer().post('/api/staff/login', payload)
    return loginResponseSchema.parse(data)
  } catch (error) {
    // eslint-disable-next-line unicorn/no-useless-promise-resolve-reject
    return Promise.reject(error)
  }
}
