{
  "openapi": "3.1.0",
  "info": {
    "title": "XCInsight API",
    "version": "1.0.0",
    "description": "Versioned API for paragliding IGC flight analysis, replay data, thermals, scores, weather context, AI debriefs, secure sharing and signed developer webhooks."
  },
  "servers": [
    {
      "url": "https://xcinsight.com/api/v1"
    }
  ],
  "components": {
    "securitySchemes": {
      "bearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "xci_live_*"
      }
    },
    "schemas": {
      "Flight": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "description": "Non-sequential ULID"
          },
          "title": {
            "type": "string"
          },
          "site": {
            "type": [
              "string",
              "null"
            ]
          },
          "flown_at": {
            "type": [
              "string",
              "null"
            ],
            "format": "date-time"
          },
          "duration_seconds": {
            "type": "integer"
          },
          "metrics": {
            "type": "object"
          },
          "quality": {
            "type": "object"
          }
        }
      },
      "Error": {
        "type": "object",
        "properties": {
          "message": {
            "type": "string"
          },
          "code": {
            "type": "string"
          }
        }
      }
    }
  },
  "security": [
    {
      "bearerAuth": []
    }
  ],
  "paths": {
    "/health": {
      "get": {
        "security": [],
        "summary": "API health",
        "responses": {
          "200": {
            "description": "OK"
          }
        }
      }
    },
    "/me": {
      "get": {
        "summary": "Current pilot",
        "responses": {
          "200": {
            "description": "Pilot profile"
          }
        }
      }
    },
    "/usage": {
      "get": {
        "summary": "Current API allowance",
        "responses": {
          "200": {
            "description": "Usage"
          }
        }
      }
    },
    "/flights": {
      "get": {
        "summary": "List flights",
        "responses": {
          "200": {
            "description": "Flight list"
          }
        }
      },
      "post": {
        "summary": "Upload IGC flight",
        "requestBody": {
          "required": true,
          "content": {
            "multipart/form-data": {
              "schema": {
                "type": "object",
                "required": [
                  "igc"
                ],
                "properties": {
                  "igc": {
                    "type": "string",
                    "format": "binary"
                  },
                  "title": {
                    "type": "string"
                  },
                  "site": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Processed flight"
          }
        }
      }
    },
    "/flights/{flightId}": {
      "get": {
        "summary": "Flight detail",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Flight"
          }
        }
      }
    },
    "/flights/{flightId}/track": {
      "get": {
        "summary": "Processed replay/track payload",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Track"
          }
        }
      }
    },
    "/flights/{flightId}/thermals": {
      "get": {
        "summary": "Thermal analytics",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Thermals"
          }
        }
      }
    },
    "/flights/{flightId}/score": {
      "get": {
        "summary": "Flight score",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Score"
          }
        }
      }
    },
    "/flights/{flightId}/weather": {
      "get": {
        "summary": "Saved weather/environment context",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Weather"
          }
        }
      }
    },
    "/flights/{flightId}/analysis": {
      "get": {
        "summary": "Saved AI debrief",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Analysis"
          }
        }
      },
      "post": {
        "summary": "Run AI debrief",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Analysis"
          },
          "429": {
            "description": "AI allowance exhausted"
          }
        }
      }
    },
    "/flights/{flightId}/sharing": {
      "get": {
        "summary": "Share state",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Share state"
          }
        }
      },
      "post": {
        "summary": "Enable secure unlisted sharing",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Share state"
          }
        }
      },
      "delete": {
        "summary": "Disable sharing",
        "parameters": [
          {
            "name": "flightId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Disabled"
          }
        }
      }
    }
  },
  "webhooks": {
    "xcinsightEvent": {
      "post": {
        "summary": "XCInsight signed event delivery",
        "description": "Webhook endpoints are configured in Developer Platform. Verify X-XCInsight-Signature as HMAC-SHA256(timestamp + \".\" + raw request body, signing secret).",
        "parameters": [
          {
            "in": "header",
            "name": "X-XCInsight-Event",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "X-XCInsight-Delivery",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "X-XCInsight-Timestamp",
            "required": true,
            "schema": {
              "type": "string"
            }
          },
          {
            "in": "header",
            "name": "X-XCInsight-Signature",
            "required": true,
            "schema": {
              "type": "string",
              "example": "v1=..."
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "id",
                  "type",
                  "api_version",
                  "created_at",
                  "data"
                ],
                "properties": {
                  "id": {
                    "type": "string",
                    "example": "evt_01..."
                  },
                  "type": {
                    "type": "string",
                    "example": "flight.analysis.completed"
                  },
                  "api_version": {
                    "type": "string",
                    "example": "v1"
                  },
                  "created_at": {
                    "type": "string",
                    "format": "date-time"
                  },
                  "data": {
                    "type": "object",
                    "additionalProperties": true
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Event accepted"
          },
          "204": {
            "description": "Event accepted"
          }
        }
      }
    }
  }
}
