@JS struct DataPoint {
    let x: Double
    let y: Double
    var label: String
    var optCount: Int?
    var optFlag: Bool?

    @JS init(x: Double, y: Double, label: String, optCount: Int?, optFlag: Bool?)
}

@JS struct Address {
    var street: String
    var city: String
    var zipCode: Int?
}

@JS struct Person {
    var name: String
    var age: Int
    var address: Address
    var email: String?
}

@JS class Greeter {
    @JS var name: String

    @JS init(name: String)
    @JS func greet() -> String
}

@JS struct Session {
    var id: Int
    var owner: Greeter
}

@JS func roundtrip(_ session: Person) -> Person

@JS enum Precision: Float {
    case rough = 0.1
    case fine = 0.001
}

@JS struct Measurement {
    var value: Double
    var precision: Precision
    var optionalPrecision: Precision?
}

@JS struct ConfigStruct {
    @JS static let maxRetries: Int = 3
    @JS nonisolated(unsafe) static var defaultConfig: String = "production"
    @JS nonisolated(unsafe) static var timeout: Double = 30.0
    @JS static var computedSetting: String { "Config: \(defaultConfig)" }
    @JS static func update(_ timeout: Double) -> Double
}

@JS struct Container {
    var object: JSObject
    var optionalObject: JSObject?
}

@JS func roundtripContainer(_ container: Container) -> Container

@JS struct Vector2D {
    var dx: Double
    var dy: Double
}

extension Vector2D {
    @JS func magnitude() -> Double {
        return (dx * dx + dy * dy).squareRoot()
    }

    @JS func scaled(by factor: Double) -> Vector2D {
        return Vector2D(dx: dx * factor, dy: dy * factor)
    }
}

extension DataPoint {
    @JS static func origin() -> DataPoint {
        return DataPoint(x: 0, y: 0, label: "origin", optCount: nil, optFlag: nil)
    }

    @JS static var dimensions: Int { 2 }
}
