import axiosInstance from '@/config/axios' import { texts } from '@/texts' import { API_ROUTES } from '@/services/config' import { createServiceError, errorResult, handleServiceError, type ServiceCallOptions, type ServiceResult, shouldBubbleErrorToParent, successResult, } from '@/services/errorHandler' import { unwrapApiData, type ApiResponse } from '@/services/apiResponse' export interface ContactMessage { id: string fullName: string mobile: string subject: string message: string readAt: string | null readBy: string | null createdAt: string } export interface CreateContactMessagePayload { fullName: string mobile: string subject: string message: string arcaptchaToken: string } export const CREATE_CONTACT_MESSAGE = async ( payload: CreateContactMessagePayload, options?: ServiceCallOptions ): Promise> => { try { const res = await axiosInstance.post>(API_ROUTES.CONTACT_MESSAGES.CREATE, payload) const body = res.data if (!body.success) { throw createServiceError(body.message || texts.chats.sendFailed) } const data = unwrapApiData(body) if (!data?.id) { throw createServiceError(texts.common.invalidServerResponse) } return successResult(data) } catch (error) { const normalizedError = handleServiceError(error, options) if (shouldBubbleErrorToParent(options)) { throw normalizedError } return errorResult(normalizedError) } }