{
  "tournament": {
    "attributes": <%= @tournament.attributes.to_json %>,
    "schools": <%= @tournament.schools.map(&:attributes).to_json %>,
    "weights": <%= @tournament.weights.map(&:attributes).to_json %>,
    "mats": <%= @tournament.mats.map(&:attributes).to_json %>,
    "wrestlers": <%= @tournament.wrestlers.map { |wrestler| wrestler.attributes.merge(
      {
        "school": wrestler.school&.attributes,
        "weight": wrestler.weight&.attributes
      }
    ) }.to_json %>,
    "matches": <%= @tournament.matches.sort_by(&:bout_number).map { |match| match.attributes.merge(
      {
        "w1_name": Wrestler.find_by(id: match.w1)&.name,
        "w2_name": Wrestler.find_by(id: match.w2)&.name,
        "winner_name": Wrestler.find_by(id: match.winner_id)&.name,
        "weight": Weight.find_by(id: match.weight_id)&.attributes,
        "mat": Mat.find_by(id: match.mat_id)&.attributes
      }
    ) }.to_json %>
  }
}