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

import UIKit

class YHWorkIntroductionViewModel: YHBaseViewModel {
    var introducetionExampleModels: [YHWorkExampleModel]?

    override init() {
        super.init()
    }
    
    func requestIntroducetionExample(callBackBlock:@escaping (_ success: Bool?, _ error:YHErrorModel?)->()) {
        let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.WorkExperience.projectExample
        let _ = YHNetRequest.getRequest(url: strUrl) { [weak self] json, code in
            //1. json字符串 转 对象
            guard let self = self else { return }
            let dic = json.data
            guard let result = [YHWorkExampleModel].deserialize(from: dic as? [Any]) else {
                callBackBlock(false,nil)
                return
            }
            self.introducetionExampleModels = result as? [YHWorkExampleModel]
            callBackBlock(true, nil)
        } failBlock: { err in
            callBackBlock(false,err)
        }
    }
    
    // 0保存 1下一步
    func saveWorkProjectDetail(_ workModel: YHWorkExperienceDetailModel, projectModel: YHWorkExperienceProjectModel, callBackBlock:@escaping (_ success: Bool?, _ error:YHErrorModel?)->()) {
        let params: [String : Any] = ["app_id": workModel.create_from_appid,
                                      "id": projectModel.id ?? 0,
                                      "order_id": workModel.order_id,
                                      "project_end_time": projectModel.project_end_time ?? "",
                                      "project_highlights": projectModel.project_highlights ?? 0,
                                      "project_name": projectModel.project_name ?? 0,
                                      "project_start_time": projectModel.project_start_time ?? "",
                                      "work_id": workModel.id
                                    ]
        let strUrl = YHBaseUrlManager.shared.curURL() + YHAllApiName.WorkExperience.saveProject
        let _ = YHNetRequest.postRequest(url: strUrl, params: params) { [weak self] json, code in
            guard let self = self else { return }
            callBackBlock(true, nil)
        } failBlock: { err in
            callBackBlock(false, err)
        }
    }
}

