//
//  CreatorCommunityRepository.swift
//  SodaLive
//
//  Created by klaus on 2023/12/19.
//

import Foundation
import CombineMoya
import Combine
import Moya

class CreatorCommunityRepository {
    private let api = MoyaProvider<CreatorCommunityApi>()
    
    func createCommunityPost(parameters: [MultipartFormData]) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.createCommunityPost(parameters: parameters))
    }
    
    func modifyCommunityPost(parameters: [MultipartFormData]) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.modifyCommunityPost(parameters: parameters))
    }
    
    func getCommunityPostList(creatorId: Int, page: Int, size: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCommunityPostList(creatorId: creatorId, page: page, size: size))
    }
    
    func getCommunityPostDetail(postId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCommunityPostDetail(postId: postId))
    }
    
    func communityPostLike(postId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.communityPostLike(postId: postId))
    }
    
    func createCommunityPostComment(comment: String, postId: Int, parentId: Int?) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.createCommunityPostComment(comment: comment, postId: postId, parentId: parentId))
    }
    
    func getCommunityPostCommentList(postId: Int, page: Int, size: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCommunityPostCommentList(postId: postId, page: page, size: size))
    }
    
    func getCommentReplyList(commentId: Int, page: Int, size: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getCommentReplyList(commentId: commentId, page: page, size: size))
    }
    
    func modifyComment(request: ModifyCommunityPostCommentRequest) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.modifyComment(request: request))
    }
    
    func getLatestPostListFromCreatorsYouFollow() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getLatestPostListFromCreatorsYouFollow)
    }
    
    func purchaseCommunityPost(postId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.purchaseCommunityPost(postId: postId))
    }
}
