"use client"; import { ChatHistoryResponse, ChatSendResponse, SendMessageRequest, UnlockHistoryResponse, UnlockPrivateRequest, UnlockPrivateResponse, } from "@/data/dto/chat"; import type { ChatApi } from "@/data/services/api"; import type { UnlockPrivateMessageInput } from "@/data/repositories/interfaces"; import { Result } from "@/utils"; export class ChatRemoteDataSource { constructor(private readonly api: ChatApi) {} async sendMessage( message: string, options?: { image?: string; useWebSocket?: boolean }, ): Promise> { return Result.wrap(async () => { const request = SendMessageRequest.from({ message, image: options?.image ?? "", useWebSocket: options?.useWebSocket ?? false, }); return await this.api.sendMessage(request); }); } async getHistory( limit = 50, offset = 0, ): Promise> { return Result.wrap(() => this.api.getHistory(limit, offset)); } async unlockPrivateMessage( input: UnlockPrivateMessageInput, ): Promise> { return Result.wrap(() => this.api.unlockPrivateMessage(UnlockPrivateRequest.from(input)), ); } async unlockHistory(): Promise> { return Result.wrap(() => this.api.unlockHistory()); } }