//
//  AccountAuthViewModel.swift

//
//  Created by Leon on 2025/8/4.
//

import Foundation

class AccountAuthViewModel{
    var authProcessAction: ((_ code:String , _ type: String ) -> Void)?
 
    func thirdLogin(code: String?, type: String?, _ completion:((_ state:Bool, _ token: String)->Void)?){
        guard let thirdCode = code, let thirdType = type else {
            assert(false)
            return
        }
        Hud.showIndicator()
        let params = ["thirdType":thirdType, "thirdToken": thirdCode]
        LoginProvider.request(LoginAPI.loginByThird(params: params), modelType: ThirdLoginResponse.self) { [weak self] result in
            switch result {
            case let .success(content):
                // dlog("mock user: \(String(describing: content)), user's token: \(String(describing: content?.token))")
                guard let userToken = content?.token else { return }
                UserCore.shared.updateToken(tokenNew: userToken)

                completion?(true, userToken)
            case .failure:
                Hud.hideIndicator()
                completion?(false, "")
                break
            }
        }
    }
}
