//
//  YHCertificateViewModel.swift
//  galaxy
//
//  Created by edy on 2024/3/15.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHCertificateViewModel: NSObject {
    
    func getUploadCertificateList(isSilient:Bool = false, callBack:@escaping (_ listInfo: YHUploadCertificateInfo?, _ error:YHErrorModel?)->()) {
        
        let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Family.familyInfoApi
        
        if !isSilient {
            YHHUD.show(.progress(message: "数据加载中..."))
        }
         
        let params = ["id": 0]
        let _ = YHNetRequest.getRequest(url: strUrl, params:params) { json, code in
            
            if !isSilient {
                YHHUD.hide()
            }
                         
            printLog("model 是 ==> \(json)")
            let dic = json.data
            
            if code == NetWorkCode.success.rawValue {
                guard let result = YHUploadCertificateInfo.deserialize(dict: dic as? Dictionary ) else {
                    callBack(nil, YHErrorModel(errorCode:Int32(json.code), errorMsg:"解析失败".local))
                    return
                }
                callBack(result, nil)
                
            } else {
                let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
                callBack(nil, error)
            }
            
        } failBlock: { err in
            callBack(nil, err)
        }
    }
}
