// LANG-COMP-013-03: Tuples in Functions - Parameters and return values
// Demonstrates using tuples with functions

fn main() {
    // Function returning a tuple
    fn get_coordinates() -> (i32, i32) {
        (100, 200)
    }

    let coords = get_coordinates()
    println(coords)

    // Function taking tuple parameter
    fn print_point(point: (i32, i32)) {
        println(f"Point: ({point.0}, {point.1})")
    }

    print_point((5, 10))

    // Function with tuple destructuring in parameters
    fn calculate_distance(p1: (i32, i32), p2: (i32, i32)) -> i32 {
        let dx = p2.0 - p1.0
        let dy = p2.1 - p1.1
        dx * dx + dy * dy  // Squared distance
    }

    let dist = calculate_distance((0, 0), (3, 4))
    println(dist)

    // Multiple return values
    fn get_quotient_and_remainder(dividend: i32, divisor: i32) -> (i32, i32) {
        (dividend / divisor, dividend % divisor)
    }

    let result = get_quotient_and_remainder(17, 5)
    let q = result.0
    let r = result.1
    println(f"17 / 5 = {q} remainder {r}")

    // Function returning different types in tuple
    fn create_user_tuple() -> (i32, String, bool) {
        let name: String = "Alice"
        let tuple = (42, name, true)
        tuple
    }

    let info = create_user_tuple()
    let id = info.0
    let username = info.1
    let active = info.2
    println(id)
    println(username)
    println(active)
}
