//
//  SpeakPracticeNetViewModel.swift
//  SpeakEasyLearnEnglish
//
//  Created by edy on 2025/7/25.
//

import UIKit
import Moya


class SpeakPracticeNetViewModel: NetworkUtil<PracticeAPI> {

}

enum PracticeAPI : BaseTargetType {
    case login([String:Any])
    
}


extension PracticeAPI {
    
    var baseURL: URL {
        return URL(string: "https://feedapihk.zhangxinhulian.com")!
    }
    
    var path: String {
        switch self {
        case .login:
            return "/api/learn/user/login"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .login:
            return .get
        }
    }
    
    var task: Task {
        switch self {
        case .login(let param):
            do {
                let pramdata = try JSONSerialization.data(withJSONObject: param)
                return .requestCompositeData(bodyData: pramdata, urlParameters: param)
            }catch{
                return .requestParameters(parameters: param, encoding: URLEncoding.httpBody)
            }
        }
    }
    
    var headers: [String: String]? {
        switch self {
        case .login:
            return ["Content-Type": "application/json",
                    "Authorization":SpeakElePublicManager.share.PublicData.userInfo.token ?? ""]
        }
    }
}
