{
  "$type": "com.atproto.lexicon.schema",
  "defs": {
    "externalTrailIds": {
      "properties": {
        "cotrexId": {
          "description": "COTREX trail feature identifier.",
          "type": "string"
        },
        "osmRelationId": {
          "description": "OpenStreetMap relation identifier.",
          "type": "string"
        },
        "osmWayId": {
          "description": "OpenStreetMap way identifier.",
          "type": "string"
        },
        "usfsTrailNumber": {
          "description": "United States Forest Service trail identifier.",
          "type": "string"
        }
      },
      "type": "object"
    },
    "gradeStats": {
      "properties": {
        "avgGradePct": {
          "description": "Mean gradient percentage (as a decimal string, e.g. '12.5').",
          "type": "string"
        },
        "climbCategory": {
          "description": "Standard climb category rating.",
          "knownValues": [
            "HC",
            "1",
            "2",
            "3",
            "4",
            "uncategorized"
          ],
          "type": "string"
        },
        "maxGradePct": {
          "description": "Peak gradient percentage (as a decimal string, e.g. '18.2').",
          "type": "string"
        }
      },
      "type": "object"
    },
    "main": {
      "description": "A competitive trail timing segment with defined start/finish gates.",
      "key": "tid",
      "record": {
        "properties": {
          "createdAt": {
            "description": "Segment creation timestamp.",
            "format": "datetime",
            "type": "string"
          },
          "description": {
            "description": "Optional notes or description of the segment terrain.",
            "maxGraphemes": 2000,
            "maxLength": 20000,
            "type": "string"
          },
          "directionality": {
            "default": "forward",
            "description": "Directionality of timing traversal.",
            "knownValues": [
              "forward",
              "reverse",
              "out_and_back"
            ],
            "type": "string"
          },
          "endGate": {
            "description": "End timing gate coordinate and tolerance radius.",
            "ref": "#timingGate",
            "type": "ref"
          },
          "geometry": {
            "description": "Canonical polyline geometry for map matching.",
            "ref": "#simplifiedLineString",
            "type": "ref"
          },
          "gradeStats": {
            "description": "Gradient statistics and climb category.",
            "ref": "#gradeStats",
            "type": "ref"
          },
          "labels": {
            "description": "Optional self-label values the author applies to this record, effectively content warnings (e.g. graphic-media for an injury photo).",
            "refs": [
              "com.atproto.label.defs#selfLabels"
            ],
            "type": "union"
          },
          "langs": {
            "description": "Optional. The human languages of this record's text (the title and description), as BCP-47 tags, so consumers can filter or translate.",
            "items": {
              "format": "language",
              "type": "string"
            },
            "maxLength": 3,
            "type": "array"
          },
          "physicalTrailRef": {
            "description": "Public authoritative trail registry cross-references (OSM, COTREX, USFS).",
            "ref": "#externalTrailIds",
            "type": "ref"
          },
          "segmentType": {
            "description": "Type or profile category of the segment.",
            "knownValues": [
              "climb",
              "descent",
              "sprint",
              "trail",
              "traverse"
            ],
            "type": "string"
          },
          "sourceActivityRef": {
            "description": "Optional reference to the source activity from which the segment was extracted.",
            "ref": "com.atproto.repo.strongRef",
            "type": "ref"
          },
          "sport": {
            "description": "Primary sport class for this segment (e.g. mountain_bike, trail_run).",
            "type": "string"
          },
          "startGate": {
            "description": "Start timing gate coordinate and tolerance radius.",
            "ref": "#timingGate",
            "type": "ref"
          },
          "title": {
            "description": "Title or display name of the segment.",
            "maxGraphemes": 300,
            "maxLength": 3000,
            "type": "string"
          }
        },
        "required": [
          "title",
          "segmentType",
          "sport",
          "startGate",
          "endGate",
          "directionality",
          "geometry",
          "createdAt"
        ],
        "type": "object"
      },
      "type": "record"
    },
    "simplifiedLineString": {
      "properties": {
        "coordinates": {
          "description": "Polyline coordinate tuples array.",
          "items": {
            "items": {
              "type": "string"
            },
            "type": "array"
          },
          "maxLength": 500,
          "type": "array"
        },
        "type": {
          "const": "LineString",
          "description": "GeoJSON LineString type.",
          "type": "string"
        }
      },
      "required": [
        "type",
        "coordinates"
      ],
      "type": "object"
    },
    "timingGate": {
      "properties": {
        "coordinate": {
          "description": "Timing gate coordinate tuple [lon, lat, ele?].",
          "items": {
            "type": "string"
          },
          "type": "array"
        },
        "radiusMeters": {
          "default": 25,
          "description": "Snapping radius in meters around the gate coordinate.",
          "maximum": 200,
          "minimum": 5,
          "type": "integer"
        }
      },
      "required": [
        "coordinate"
      ],
      "type": "object"
    }
  },
  "id": "world.treeline.segment.record",
  "lexicon": 1
}
