export function usePublicRequest() {
  const config = useRuntimeConfig()

  async function fetchRequest(token) {
    const response = await $fetch(`${config.public.apiBaseUrl}/public-requests/${token}`)
    return response?.data || {}
  }

  async function createOfferPortal(token, offerId, endpoint) {
    const url = endpoint || `${config.public.apiBaseUrl}/public-requests/${token}/offers/${offerId}/portal`
    const response = await $fetch(url, {
      method: 'POST',
    })

    return response?.data || {}
  }

  return {
    createOfferPortal,
    fetchRequest,
  }
}
