//
//  ExplorerRepository.swift
//  SodaLive
//
//  Created by klaus on 2023/08/10.
//

import Foundation
import CombineMoya
import Combine
import Moya

final class ExplorerRepository {
    private let api = MoyaProvider<ExplorerApi>()
    
    func getExplorer() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getExplorer)
    }
    
    func searchChannel(channel: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.searchChannel(channel: channel))
    }
    
    func getCreatorProfile(id: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(
            .getCreatorProfile(
                userId: id,
                isAdultContentVisible: UserDefaults.isAdultContentVisible()
            )
        )
    }
    
    func getFollowerList(userId: Int, page: Int, size: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getFollowerList(userId: userId, page: page, size: size))
    }
    
    func getCreatorProfileCheers(userId: Int, page: Int, size: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCreatorProfileCheers(userId: userId, page: page, size: size))
    }
    
    func writeCheers(parentCheersId: Int?, creatorId: Int, content: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.writeCheers(parentCheersId: parentCheersId, creatorId: creatorId, content: content))
    }
    
    func modifyCheers(cheersId: Int, content: String?, isActive: Bool?) -> AnyPublisher<Response, MoyaError> {
        let request = PutModifyCheersRequest(cheersId: cheersId, content: content, isActive: isActive)
        return api.requestPublisher(.modifyCheers(request: request))
    }
    
    func writeCreatorNotice(notice: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.writeCreatorNotice(request: PostCreatorNoticeRequest(notice: notice)))
    }
    
    func getCreatorProfileDonationRanking(userId: Int, page: Int, size: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCreatorProfileDonationRanking(userId: userId, page: page, size: size))
    }
}