//
//  YHCompanyViewModel.swift
//  galaxy
//
//  Created by EDY on 2024/2/22.
//  Copyright © 2024 https://www.galaxy-immi.com. All rights reserved.
//

import UIKit

class YHCompanyViewModel: YHBaseViewModel {
    override init() {
        super.init()
    }
    
    func requestCompany(_ key: String, callBackBlock:@escaping (_ success: [YHCompanyModelListModel]?, _ error:YHErrorModel?)->()) {
        let strUrl = YHBaseUrlManager.shared.curURL() + "frontend/workInfo/company-search?company=\(key)&page_size=20"
        YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
            //1. json字符串 转 对象
            guard let self = self else { return }
            guard let model = NetBaseModel.deserialize(dict: json) else {
                let error : YHErrorModel = YHErrorModel(errorCode:YHErrorCode.dictParseError.rawValue,errorMsg: YHErrorCode.dictParseError.description())
                
                callBackBlock([],error)
                return
            }
            let dic = model.data?.peel
            guard let result = YHCompanyModel.deserialize(dict: dic as? [AnyHashable : Any]) else {
                callBackBlock([],nil)
                return
            }
            
            callBackBlock(result.data, nil)
        } failBlock: { err in
            callBackBlock([],err)
        }

    }
}

