import axios from "axios"; const port = process.env.EVENT_PORT; const basePath = process.env.IS_LOCAL === "true" ? `http://127.0.0.1:${port}` : "http://event"; const eventUrl = `${basePath}/event`; export class EventClient { async getEventById(params: { token: string; accountId: string; eventId: string }) { const { token, accountId, eventId } = params; const response = await axios.get(`${eventUrl}/getById/${accountId}/${eventId}`, { headers: { jwt: `${token}` }, }); return response?.data; } async getEventsByIds(params: { token: string; marketplaceId: string; eventIds: string[] }) { const { token, marketplaceId, eventIds } = params; const response = await axios.post(`${eventUrl}/getByIds/${marketplaceId}`, { eventIds }, { headers: { jwt: `${token}` } }); return response?.data; } async getEventsByMarketplaceId(params: { marketplaceId: string; limit: number; from?: string; to?: string }) { const { limit, marketplaceId, from, to } = params; const response = await axios.get(`${eventUrl}/getEventsByMarketplace/${marketplaceId}?limit=${limit}`, { params: { from, to, }, }); return response?.data; } async getEventsBySeller(params: { token: string; sellerId: string; limit?: number; from?: string; to?: string }) { const response = await axios.get(`${eventUrl}/getEventsBySeller/${params.sellerId}`, { headers: { jwt: params.token }, params: { limit: params.limit, from: params.from, to: params.to, }, }); return response?.data; } async getEventsByDateRange(params: { from: string; to: string; token: string; isEnabled: boolean; isReminderOn?: boolean }) { const response = await axios.get(`${eventUrl}/getEventsByDate`, { headers: { jwt: params.token }, params: { from: params.from, to: params.to, isReminderOn: params.isReminderOn, isEnabled: params.isEnabled, }, }); return response?.data; } async getEventsByType(params: { eventType: string; sellerId: string; marketplaceId: string; jwt: string }) { const { eventType, sellerId, marketplaceId, jwt } = params; const response = await axios.get(`${eventUrl}/getEventsByType/${marketplaceId}/${sellerId}/${eventType}`, { headers: { jwt }, }); return response?.data; } async checkTimeSlotCapacity(params: { token: string; eventId: string; date: string; startTime: string; quantity: number; }): Promise<{ hasCapacity: boolean; available: number; total: number; requested: number }> { const { token, eventId, date, startTime, quantity } = params; const response = await axios.post( `${eventUrl}/${eventId}/time-slot/check-capacity`, { date, startTime, quantity }, { headers: { jwt: token } } ); return response?.data; } }