//
//  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 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)))
    }
}
