import Foundation
import CoreLocation

@objc(UTSSDKModulesBmapLocCLErrorHelper)
@objcMembers
public class CLErrorHelper: NSObject {

    /**
     * 获取CLError错误码
     */
    @objc public static func getCLErrorCode(_ error: NSError) -> Int {
        return error.code
    }

    /**
     * 将NSError的userInfo字典解析为字符串
     */
    @objc public static func getCLErrorDescription(_ error: NSError) -> String {
        let userInfo = error.userInfo
        var userInfoStr = ""
        for (key, value) in userInfo {
            let valueStr = String(describing: value)
            userInfoStr += "\(valueStr)。 "
        }
        return userInfoStr
    }

    /**
     * 将CLLocation的timestamp对象转换为字符串形式
     */
    @objc public static func formatLocationTimestamp(_ location: CLLocation) -> String {
        let formatter = DateFormatter()
        formatter.dateFormat = "yyyy-MM-dd HH:mm:ss"
        return formatter.string(from: location.timestamp)
    }
}
