//! returns: 129
//! Test array of record constants.

record Point: Copy {
    x: i32,
    y: i32,
}

// A constant array of structs
constant POINTS: [Point; 3] = [
    Point { x: 1, y: 2 },
    Point { x: 3, y: 4 },
    Point { x: 5, y: 6 }
];

fn sumPoints(points: [Point; 3]) -> i32 {
    let mut sum: i32 = 0;

    for p in (points) {
        set sum += p.x + p.y;
    }
    return sum;
}

// Array of structs as a function parameter
fn checkPoints(points: [Point; 3]) -> bool {
    return (points[0].x == POINTS[0].x and
            points[1].y == POINTS[1].y and
            points[2].x == POINTS[2].x);
}

@default fn main() -> i32 {
    // Sum all x and y values: (1 + 2) + (3 + 4) + (5 + 6) = 21
    let total: i32 = sumPoints(POINTS);

    // Create a modified array of points
    let morePoints: [Point; 3] = [
        Point { x: 10, y: 11 },
        Point { x: 12, y: 13 },
        Point { x: 14, y: 15 }
    ];

    // Sum of morePoints: (10 + 11) + (12 + 13) + (14 + 15) = 75
    let moreTotal: i32 = sumPoints(morePoints);

    // Verify that checkPoints works
    let isValid: bool = checkPoints(POINTS);

    if (isValid) {
      return total + (moreTotal - total) * 2;
    }
    return 1;
}
