62 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Swift
		
	
	
	
	
	
//
 | 
						|
//  ChatRoomRepository.swift
 | 
						|
//  SodaLive
 | 
						|
//
 | 
						|
//  Created by klaus on 9/2/25.
 | 
						|
//
 | 
						|
 | 
						|
import Foundation
 | 
						|
import CombineMoya
 | 
						|
import Combine
 | 
						|
import Moya
 | 
						|
 | 
						|
class ChatRoomRepository {
 | 
						|
    private let talkApi = MoyaProvider<TalkApi>()
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * 채팅방 입장: 서버 캐릭터 정보 + 최신 메시지 수신
 | 
						|
     */
 | 
						|
    func enterChatRoom(roomId: Int, characterImageId: Int?) -> AnyPublisher<Response, MoyaError> {
 | 
						|
        return talkApi.requestPublisher(.enterChatRoom(roomId: roomId, characterImageId: characterImageId))
 | 
						|
    }
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * 점진적 메시지 로딩: 커서 기반으로 이전 메시지를 조회
 | 
						|
     */
 | 
						|
    func loadMoreMessages(roomId: Int, cursor: Int?) -> AnyPublisher<Response, MoyaError> {
 | 
						|
        return talkApi.requestPublisher(.getChatRoomMessages(roomId: roomId, cursor: cursor, limit: 20))
 | 
						|
    }
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * 메시지 전송 API 호출
 | 
						|
     * - 성공 시: 서버에서 내려온 메시지를 로컬에 반영한다.
 | 
						|
     * - 반환: 서버에서 내려온 메시지(ServerChatMessage) (대개 AI 응답일 것으로 가정)
 | 
						|
     */
 | 
						|
    func sendMessage(roomId: Int, message: String) -> AnyPublisher<Response, MoyaError> {
 | 
						|
        return talkApi.requestPublisher(.sendMessage(roomId: roomId, request: SendChatMessageRequest(message: message)))
 | 
						|
    }
 | 
						|
    
 | 
						|
    /**
 | 
						|
     * 유료 메시지 구매
 | 
						|
     * - 성공 시 서버에서 갱신된 메시지를 반환
 | 
						|
     */
 | 
						|
    func purchaseMessage(roomId: Int, messageId: Int64) -> AnyPublisher<Response, MoyaError> {
 | 
						|
        return talkApi.requestPublisher(
 | 
						|
            .purchaseMessage(
 | 
						|
                roomId: roomId,
 | 
						|
                messageId: messageId,
 | 
						|
                request: ChatMessagePurchaseRequest()
 | 
						|
            )
 | 
						|
        )
 | 
						|
    }
 | 
						|
    
 | 
						|
    /** 쿼터 상태 조회 */
 | 
						|
    func getChatQuotaStatus() -> AnyPublisher<Response, MoyaError> {
 | 
						|
        return talkApi.requestPublisher(.getChatQuotaStatus)
 | 
						|
    }
 | 
						|
    
 | 
						|
    func purchaseChatQuota() -> AnyPublisher<Response, MoyaError> {
 | 
						|
        return talkApi.requestPublisher(.purchaseChatQuota(request: ChatQuotaPurchaseRequest()))
 | 
						|
    }
 | 
						|
}
 |