 import Foundation
 
 public struct LayoutMetrics: Equatable {
+
+    private enum JSONKey: JSONKeyType {
+        case top, left, bottom, right, spaceH, spaceV
+    }
 
     public let top: CGFloat
     public let left: CGFloat

    }
}

public func ==(lhs: Layout, rhs: Layout) -> Bool {
    return lhs.formats == rhs.formats && lhs.metrics == rhs.metrics && lhs.options == rhs.options
}

    }

    public init(top: CGFloat = 0, left: CGFloat = 0, bottom: CGFloat = 0, right: CGFloat = 0, spaceH: CGFloat = 0, spaceV: CGFloat = 0, customMetrics: [String: CGFloat] = [:]) {

        self.top = customMetrics[JSONKey.top.asString] ?? top
        self.left = customMetrics[JSONKey.left.asString] ?? left
        self.bottom = customMetrics[JSONKey.bottom.asString] ?? bottom
        self.right = customMetrics[JSONKey.right.asString] ?? right
        self.spaceH = customMetrics[JSONKey.spaceH.asString] ?? spaceH
        self.spaceV = customMetrics[JSONKey.spaceV.asString] ?? spaceV


        self.customMetrics = customMetrics.filter({ (key, value) -> Bool in
            let top = key != JSONKey.top.asString
            let left = key != JSONKey.left.asString
            let bottom = key != JSONKey.bottom.asString
            let right = key != JSONKey.right.asString
            let spaceH = key != JSONKey.spaceH.asString
            let spaceV = key != JSONKey.spaceV.asString
            return top && left && bottom && right && spaceH && spaceV
        })
    }

    func metrics() -> [String: CGFloat] {
        let standardMetrics = [JSONKey.top.asString: top,
                               JSONKey.left.asString: left,
                               JSONKey.bottom.asString: bottom,
                               JSONKey.right.asString: right,
                               JSONKey.spaceH.asString: spaceH,
                               JSONKey.spaceV.asString: spaceV].filter { (key, value) -> Bool in
                                return value != 0.0
        }

        return customMetrics + standardMetrics
    }
}

