//
//  NetworkManager.swift
//  wallpaper_project
//
//  Created by 忆海16 on 2024/6/4.
//

import Foundation
import Alamofire

class NetworkManager {
    static let shared = NetworkManager()
    
    private init() {}
    
    /// 封装的POST请求
    /// - Parameters:
    ///   - url: 请求的URL字符串
    ///   - parameters: 请求参数
    ///   - headers: 请求头
    ///   - completion: 请求完成的回调
    func postRequest(url: String, parameters: [String: Any]?, headers: HTTPHeaders?, completion: @escaping (Result<Any, AFError>) -> Void) {
        AF.request(url,
                   method: .post,
                   parameters: parameters,
                   encoding: JSONEncoding.default,
                   headers: headers)
            .validate()
            .responseJSON { response in
                switch response.result {
                case .success(let data):
                    completion(.success(data))
                case .failure(let error):
                    completion(.failure(error))
                }
            }
    }
}

