//
//  UserOperator.swift

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


struct UserOperator{
    private init(){}
    
    /// uid: 表示aiId，如果不是则不用传，排除自己的userId
    static func checkname(name:String?, uid : Int? = nil, block:((_ nicknameOK: Bool) -> Void)?){
        let validname = name ?? ""
        var exUserId : Int? = nil
        if let paramsUid = uid{
            exUserId = paramsUid
        }else if let userId = UserCore.shared.user?.userId{
            exUserId = userId
        }
        
        UserProvider.request(.userNicknameCheck(nickname: validname, exUserId: exUserId), modelType: Bool?.self) {result in
            switch result {
            case .success(let success):
                if let checkResult = success, checkResult == false{
                    block?(true)
                }else{
                    Hud.toast(str: "该昵称已存在")
                    block?(false)
                }
            case .failure:
                block?(false)
                break
            }
        }
    }
}
