// Extensions.swift
//
// Generated by swagger-codegen
// https://github.com/swagger-api/swagger-codegen
//

import Alamofire
import PromiseKit

extension Bool: JSONEncodable {
    func encode() -> AnyObject { return self }
}

extension Float: JSONEncodable {
    func encode() -> AnyObject { return self }
}

extension Int: JSONEncodable {
    func encode() -> AnyObject { return self }
}

extension Double: JSONEncodable {
    func encode() -> AnyObject { return self }
}

extension String: JSONEncodable {
    func encode() -> AnyObject { return self }
}

private func encodeIfPossible<T>(object: T) -> AnyObject {
    if object is JSONEncodable {
        return (object as! JSONEncodable).encode()
    } else {
        return object as! AnyObject
    }
}

extension Array: JSONEncodable {
    func encode() -> AnyObject {
        return self.map(encodeIfPossible)
    }
}

extension Dictionary: JSONEncodable {
    func encode() -> AnyObject {
        var dictionary = [NSObject:AnyObject]()
        for (key, value) in self {
            dictionary[key as! NSObject] = encodeIfPossible(value)
        }
        return dictionary
    }
}
