//
//  LiveRepository.swift
//  SodaLive
//
//  Created by klaus on 2023/08/09.
//

import Foundation
import CombineMoya
import Combine
import Moya

final class LiveRepository {
    private let api = MoyaProvider<LiveApi>()
    
    func roomList(request: GetRoomListRequest) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.roomList(request: request))
    }
    
    func recentVisitRoomUsers() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.recentVisitRoomUsers)
    }
    
    func getReservations(isActive: Bool) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getReservations(isActive: isActive))
    }
    
    func getReservation(reservationId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getReservation(reservationId: reservationId))
    }
    
    func cancelReservation(reservationId: Int, reason: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.cancelReservation(request: CancelLiveReservationRequest(reservationId: reservationId, reason: reason)))
    }
    
    func getRoomDetail(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getRoomDetail(roomId: roomId))
    }
    
    func makeReservation(request: MakeLiveReservationRequest) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.makeReservation(request: request))
    }
    
    func enterRoom(request: EnterOrQuitLiveRoomRequest) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.enterRoom(request: request))
    }
    
    func getRecentRoomInfo() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getRecentRoomInfo)
    }
    
    func createRoom(parameters: [MultipartFormData]) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.createRoom(parameters: parameters))
    }
    
    func startLive(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.startLive(request: StartLiveRequest(roomId: roomId)))
    }
    
    func cancelRoom(roomId: Int, reason: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.cancelRoom(request: CancelLiveRequest(roomId: roomId, reason: reason)))
    }
    
    func editLiveRoomInfo(roomId: Int, parameters: [MultipartFormData]) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.editLiveRoomInfo(roomId: roomId, parameters: parameters))
    }
    
    func quitRoom(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.quitRoom(roomId: roomId))
    }
    
    func getRoomInfo(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getRoomInfo(roomId: roomId))
    }
    
    func donation(roomId: Int, can: Int, message: String = "", isSecret: Bool = false) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.donation(request: LiveRoomDonationRequest(roomId: roomId, can: can, message: message, isSecret: isSecret)))
    }
    
    func refundDonation(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.refundDonation(roomId: roomId))
    }
    
    func setListener(roomId: Int, userId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.setListener(request: SetManagerOrSpeakerOrAudienceRequest(roomId: roomId, memberId: userId)))
    }
    
    func setSpeaker(roomId: Int, userId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.setSpeaker(request: SetManagerOrSpeakerOrAudienceRequest(roomId: roomId, memberId: userId)))
    }
    
    func setManager(roomId: Int, userId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.setManager(request: SetManagerOrSpeakerOrAudienceRequest(roomId: roomId, memberId: userId)))
    }
    
    func kickOut(roomId: Int, userId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.kickOut(request: LiveRoomKickOutRequest(roomId: roomId, userId: userId)))
    }
    
    func donationStatus(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.donationStatus(roomId: roomId))
    }
    
    func getTotalDoantionCan(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.donationTotal(roomId: roomId))
    }
    
    func getDonationMessageList(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getDonationMessageList(roomId: roomId))
    }
    
    func deleteDonationMessage(roomId: Int, messageUUID: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.deleteDonationMessage(roomId: roomId, messageUUID: messageUUID))
    }
    
    func getUserProfile(roomId: Int, userId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getUserProfile(roomId: roomId, userId: userId))
    }
    
    func getAllMenuPreset(creatorId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getAllMenuPreset(creatorId: creatorId))
    }
    
    func likeHeart(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.likeHeart(request: LiveRoomLikeHeartRequest(roomId: roomId)))
    }
    
    func getTotalHeartCount(roomId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getTotalHeartCount(roomId: roomId))
    }
}
