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

import Foundation
import CombineMoya
import Combine
import Moya

final class UserRepository {
    private let api = MoyaProvider<UserApi>()
    
    func login(request: LoginRequest) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.login(request: request))
    }
    
    func signUp(parameters: [MultipartFormData]) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.signUp(parameters: parameters))
    }
    
    func findPassword(email: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.findPassword(request: ForgotPasswordRequest(email: email)))
    }
    
    func searchUser(nickname: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.searchUser(nickname: nickname))
    }
    
    func getMypage() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getMypage)
    }
    
    func getMemberInfo() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getMemberInfo)
    }
    
    func getMemberCan() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getMemberInfo)
    }
    
    func updateNotificationSettings(live: Bool? = nil, uploadContent: Bool? = nil, message: Bool? = nil) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(
            .notification(
                request: UpdateNotificationSettingRequest(
                    live: live,
                    uploadContent: uploadContent,
                    message: message
                )
            )
        )
    }
    
    func logout() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.logout)
    }
    
    func logoutAllDevice() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.logoutAllDevice)
    }
    
    func signOut(reason: String, password: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.signOut(request: SignOutRequest(reason: reason, password: password)))
    }
    
    func updatePushToken(pushToken: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.updatePushToken(request: PushTokenUpdateRequest(pushToken: pushToken)))
    }
    
    func creatorFollow(creatorId: Int, follow: Bool = true, notify: Bool = true) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.creatorFollow(request: CreatorFollowRequest(creatorId: creatorId, isNotify: notify, isActive: follow)))
    }
    
    func creatorUnFollow(creatorId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.creatorUnFollow(request: CreatorFollowRequest(creatorId: creatorId)))
    }
    
    func getBlockedMemberIdList() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getBlockedMemberIdList)
    }
    
    func getBlockedMemberList(page: Int, size: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getBlockedMemberList(page: page, size: size))
    }
    
    func memberBlock(userId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.memberBlock(request: MemberBlockRequest(blockMemberId: userId)))
    }
    
    func memberUnBlock(userId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.memberUnBlock(request: MemberBlockRequest(blockMemberId: userId)))
    }
    
    func getMyProfile() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getMyProfile)
    }
    
    func profileImageUpdate(parameter: MultipartFormData) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.profileImageUpdate(parameter: parameter))
    }
    
    func profileUpdate(request: ProfileUpdateRequest) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.profileUpdate(request: request))
    }
    
    func getChangeNicknamePrice() -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getChangeNicknamePrice)
    }
    
    func checkNickname(nickname: String) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.checkNickname(nickname: nickname))
    }
    
    func changeNickname(request: ProfileUpdateRequest) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.changeNickname(request: request))
    }
    
    func updateIdfa(request: IdfaUpdateRequest) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.updateIdfa(request: request))
    }
    
    func getMemberProfile(memberId: Int) -> AnyPublisher<Response, MoyaError> {
        return api.requestPublisher(.getMemberProfile(memberId: memberId))
    }
}
