//
//  YHHomePageViewModel.swift
//  galaxy
//
//  Created by davidhuangA on 2024/1/4.
//  Copyright © 2024 www.davidhuang.com. All rights reserved.
//

import UIKit

class YHHomePageViewModel : YHBaseViewModel {
    //数据源
    var configModel:YHHomeCofigMode?
}

//接口
extension YHHomePageViewModel {
    //请求首页的配置
    func getHomeConfig(callBackBlock:@escaping (_ success: Bool,_ error:YHErrorModel?)->()) {
        let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.Common.homeConfigApi
        let _ = YHNetRequest.getRequest(url: strUrl) { json, code in
            //1. json字符串 转 对象
            guard let model = NetBaseModel.deserialize(dict: json) else {
                let error : YHErrorModel = YHErrorModel(errorCode:YHErrorCode.dictParseError.rawValue,errorMsg: YHErrorCode.dictParseError.description())
                
                callBackBlock(false,error)
                return
            }
//            printLog("model 是 ==> \(model)")
            self.configModel = model.data
            
            callBackBlock(true,nil)
        } failBlock: { err in
            callBackBlock(false,err)
        }
    }
}
