import { SponsorsApiClient } from '@/lib/api/sponsors/SponsorsApiClient'; import { getWebsiteApiBaseUrl } from '@/lib/config/apiBaseUrl'; import { isProductionEnvironment } from '@/lib/config/env'; import { Result } from '@/lib/contracts/Result'; import type { Service } from '@/lib/contracts/services/Service'; import { EnhancedErrorReporter } from '@/lib/infrastructure/EnhancedErrorReporter'; import { ConsoleLogger } from '@/lib/infrastructure/logging/ConsoleLogger'; export interface AcceptSponsorshipRequestCommand { requestId: string; actorDriverId: string; } export interface RejectSponsorshipRequestCommand { requestId: string; actorDriverId: string; reason: string | null; } export type AcceptSponsorshipRequestServiceError = | 'ACCEPT_SPONSORSHIP_REQUEST_FAILED'; export type RejectSponsorshipRequestServiceError = | 'REJECT_SPONSORSHIP_REQUEST_FAILED'; export class SponsorshipRequestsService implements Service { private readonly client: SponsorsApiClient; constructor() { const baseUrl = getWebsiteApiBaseUrl(); const logger = new ConsoleLogger(); const errorReporter = new EnhancedErrorReporter(logger, { showUserNotifications: true, logToConsole: true, reportToExternal: isProductionEnvironment(), }); this.client = new SponsorsApiClient(baseUrl, errorReporter, logger); } async acceptRequest( command: AcceptSponsorshipRequestCommand, ): Promise> { try { await this.client.acceptSponsorshipRequest(command.requestId, { actorDriverId: command.actorDriverId, } as any); return Result.ok(undefined); } catch { return Result.err('ACCEPT_SPONSORSHIP_REQUEST_FAILED'); } } async rejectRequest( command: RejectSponsorshipRequestCommand, ): Promise> { try { await this.client.rejectSponsorshipRequest(command.requestId, { actorDriverId: command.actorDriverId, reason: command.reason ?? undefined, } as any); return Result.ok(undefined); } catch { return Result.err('REJECT_SPONSORSHIP_REQUEST_FAILED'); } } }