{
  "openapi": "3.0.0",
  "info": {
    "title": "Bookovia Telematics API",
    "description": "Enterprise telematics API for vehicle tracking, trip management, fleet analytics, and real-time location streaming",
    "version": "1.0.0",
    "contact": {
      "name": "API Support",
      "email": "support@bookovia.com",
      "url": "https://bookovia.com/support"
    },
    "license": {
      "name": "Proprietary",
      "url": "https://bookovia.com/license"
    }
  },
  "servers": [
    {
      "url": "https://api.bookovia.com/v1",
      "description": "Production server"
    }
  ],
  "paths": {
    "/analytics/behavior/{trip_id}": {
      "get": {
        "summary": "Analyze Driving Behavior",
        "description": "Get detailed driving behavior analysis including acceleration patterns, braking profiles, speed consistency, and predictive insights",
        "operationId": "AnalyzeDrivingBehavior",
        "parameters": [
          {
            "name": "trip_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique identifier for the trip to analyze driving behavior for"
          },
          {
            "name": "analysis_depth",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Level of analysis detail: \"basic\", \"standard\", \"comprehensive\""
          },
          {
            "name": "include_predictions",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include predictive insights and risk forecasting"
          },
          {
            "name": "include_comparisons",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include comparisons with driver's historical patterns"
          },
          {
            "name": "behavior_categories",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated list of specific behaviors to analyze: \"acceleration\", \"braking\", \"cornering\", \"speed\", \"following\", \"consistency\""
          },
          {
            "name": "segment_analysis",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to provide behavior analysis by road segment types"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the analyzed trip"
                    },
                    "analysis_timestamp": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the behavior analysis was completed"
                    },
                    "driver_id": {
                      "type": "string",
                      "description": "Driver associated with the trip"
                    },
                    "behavior_profile": {
                      "type": "object",
                      "description": "Overall driving behavior profile and characteristics\n  \n  \n    \n      Categorized driving style: \"conservative\", \"moderate\", \"aggressive\", \"sporty\", \"erratic\""
                    },
                    "consistency_rating": {
                      "type": "string",
                      "description": "Driving consistency: \"very_consistent\", \"consistent\", \"variable\", \"inconsistent\""
                    },
                    "risk_tolerance": {
                      "type": "string",
                      "description": "Assessed risk tolerance: \"very_low\", \"low\", \"moderate\", \"high\", \"very_high\""
                    },
                    "experience_indicators": {
                      "type": "object",
                      "description": "Indicators of driving experience and skill level"
                    },
                    "adaptability_score": {
                      "type": "integer",
                      "description": "Score indicating how well driver adapts to different conditions (0-100)"
                    },
                    "behavior_metrics": {
                      "type": "object",
                      "description": "Detailed metrics for specific driving behaviors\n  \n  \n    \n      Comprehensive acceleration behavior analysis"
                    },
                    "braking_analysis": {
                      "type": "object",
                      "description": "Detailed braking patterns and characteristics"
                    },
                    "cornering_analysis": {
                      "type": "object",
                      "description": "Cornering and turning behavior analysis"
                    },
                    "speed_analysis": {
                      "type": "object",
                      "description": "Speed management and compliance patterns"
                    },
                    "following_distance_analysis": {
                      "type": "object",
                      "description": "Following distance maintenance behavior"
                    },
                    "lane_discipline": {
                      "type": "object",
                      "description": "Lane keeping and changing behavior"
                    },
                    "environmental_adaptation": {
                      "type": "object",
                      "description": "Analysis of how driving behavior adapts to different conditions\n  \n  \n    \n      Behavior changes based on weather conditions"
                    },
                    "traffic_adaptation": {
                      "type": "object",
                      "description": "Driving adjustments in different traffic densities"
                    },
                    "road_type_behavior": {
                      "type": "object",
                      "description": "Behavior variations across road types (highway, city, rural)"
                    },
                    "time_of_day_patterns": {
                      "type": "object",
                      "description": "Behavior differences by time of day"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "analytics"
        ]
      }
    },
    "/analytics/harsh-events/{trip_id}": {
      "get": {
        "summary": "Analyze Harsh Events",
        "description": "Detailed analysis of harsh driving events including acceleration, braking, cornering incidents with contextual information and prevention insights",
        "operationId": "AnalyzeHarshEvents",
        "parameters": [
          {
            "name": "trip_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique identifier for the trip to analyze harsh events for"
          },
          {
            "name": "event_types",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated list of event types to analyze: \"harsh_acceleration\", \"harsh_braking\", \"harsh_cornering\", \"rapid_direction_change\""
          },
          {
            "name": "severity_threshold",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Minimum severity level to include: \"low\", \"moderate\", \"high\", \"critical\""
          },
          {
            "name": "include_context",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include environmental and situational context for each event"
          },
          {
            "name": "include_prevention",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include prevention analysis and recommendations"
          },
          {
            "name": "group_by_location",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to group events by location clusters for pattern analysis"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the analyzed trip"
                    },
                    "analysis_timestamp": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the harsh events analysis was completed"
                    },
                    "event_summary": {
                      "type": "object",
                      "description": "Overall summary of harsh events detected during the trip\n  \n  \n    \n      Total number of harsh events detected"
                    },
                    "events_by_type": {
                      "type": "object",
                      "description": "Count of events broken down by type"
                    },
                    "events_by_severity": {
                      "type": "object",
                      "description": "Count of events broken down by severity level"
                    },
                    "event_rate": {
                      "type": "number",
                      "description": "Events per kilometer or per minute of driving"
                    },
                    "severity_distribution": {
                      "type": "object",
                      "description": "Percentage distribution of event severities"
                    },
                    "harsh_events": {
                      "type": "array",
                      "description": "Detailed analysis of each harsh event detected\n  \n  \n    \n      Unique identifier for the specific event"
                    },
                    "event_type": {
                      "type": "string",
                      "description": "Type of harsh event detected"
                    },
                    "severity": {
                      "type": "string",
                      "description": "Severity level of the event"
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "Exact timestamp when the event occurred"
                    },
                    "location": {
                      "type": "object",
                      "description": "GPS coordinates where the event occurred"
                    },
                    "event_metrics": {
                      "type": "object",
                      "description": "Detailed measurements and characteristics of the event"
                    },
                    "contextual_factors": {
                      "type": "object",
                      "description": "Environmental and situational context during the event"
                    },
                    "impact_assessment": {
                      "type": "object",
                      "description": "Analysis of the event's impact on safety, comfort, and vehicle"
                    },
                    "pattern_analysis": {
                      "type": "object",
                      "description": "Analysis of patterns and trends in harsh events\n  \n  \n    \n      Time-based patterns in event occurrence"
                    },
                    "location_clusters": {
                      "type": "array",
                      "description": "Geographic clusters where multiple events occurred"
                    },
                    "trigger_analysis": {
                      "type": "object",
                      "description": "Analysis of common triggers and precursor conditions"
                    },
                    "correlation_analysis": {
                      "type": "object",
                      "description": "Correlations between different event types and conditions"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "analytics"
        ]
      }
    },
    "/analytics/safety-score/{trip_id}": {
      "get": {
        "summary": "Get Safety Score",
        "description": "Retrieve detailed safety score analysis including driving behavior metrics, risk assessment, and improvement recommendations",
        "operationId": "GetSafetyScore",
        "parameters": [
          {
            "name": "trip_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique identifier for the trip to analyze safety score for"
          },
          {
            "name": "include_breakdown",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include detailed scoring breakdown by category"
          },
          {
            "name": "include_benchmarks",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include comparison with driver/fleet/industry averages"
          },
          {
            "name": "include_recommendations",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include personalized safety improvement recommendations"
          },
          {
            "name": "compare_period",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Time period for benchmark comparison: \"30d\", \"90d\", \"1y\""
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the analyzed trip"
                    },
                    "overall_safety_score": {
                      "type": "integer",
                      "description": "Overall safety score from 0-100 (higher is safer)"
                    },
                    "score_grade": {
                      "type": "string",
                      "description": "Letter grade representation: \"A\", \"B\", \"C\", \"D\", \"F\""
                    },
                    "analysis_timestamp": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the safety analysis was completed"
                    },
                    "trip_context": {
                      "type": "object",
                      "description": "Contextual information that influenced the safety score\n  \n  \n    \n      Total trip distance"
                    },
                    "duration_minutes": {
                      "type": "number",
                      "description": "Trip duration in minutes"
                    },
                    "road_types": {
                      "type": "object",
                      "description": "Percentage breakdown by road type (highway, city, rural)"
                    },
                    "weather_conditions": {
                      "type": "string",
                      "description": "Weather conditions during the trip"
                    },
                    "traffic_density": {
                      "type": "string",
                      "description": "Average traffic density: \"light\", \"moderate\", \"heavy\""
                    },
                    "time_of_day": {
                      "type": "string",
                      "description": "Time category: \"morning\", \"midday\", \"evening\", \"night\""
                    },
                    "score_breakdown": {
                      "type": "object",
                      "description": "Detailed breakdown of safety score components\n  \n  \n    \n      Score for acceleration behavior (0-100)"
                    },
                    "braking_score": {
                      "type": "integer",
                      "description": "Score for braking behavior (0-100)"
                    },
                    "cornering_score": {
                      "type": "integer",
                      "description": "Score for cornering and turning behavior (0-100)"
                    },
                    "speed_compliance_score": {
                      "type": "integer",
                      "description": "Score for speed limit compliance (0-100)"
                    },
                    "following_distance_score": {
                      "type": "integer",
                      "description": "Score for maintaining safe following distance (0-100)"
                    },
                    "distraction_score": {
                      "type": "integer",
                      "description": "Score based on detected distraction indicators (0-100)"
                    },
                    "consistency_score": {
                      "type": "integer",
                      "description": "Score for consistent, predictable driving (0-100)"
                    },
                    "risk_factors": {
                      "type": "array",
                      "description": "Identified risk factors that negatively impacted the score\n  \n  \n    \n      Type of risk factor"
                    },
                    "severity": {
                      "type": "string",
                      "description": "Risk severity: \"low\", \"moderate\", \"high\", \"critical\""
                    },
                    "frequency": {
                      "type": "integer",
                      "description": "Number of times this risk factor occurred"
                    },
                    "score_impact": {
                      "type": "integer",
                      "description": "Points deducted from overall score"
                    },
                    "description": {
                      "type": "string",
                      "description": "Human-readable description of the risk"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "analytics"
        ]
      }
    },
    "/auth/change-password": {
      "post": {
        "summary": "Change Password",
        "description": "Change user password. Requires current password for verification. Revokes all sessions and forces re-login.",
        "operationId": "ChangePassword",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether password change was successful"
                    },
                    "message": {
                      "type": "string",
                      "description": "Confirmation message"
                    },
                    "sessions_revoked": {
                      "type": "integer",
                      "description": "Number of sessions that were revoked"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "current_password": {
                    "type": "string",
                    "description": "Current password for verification"
                  },
                  "new_password": {
                    "type": "string",
                    "description": "New password (minimum 8 characters recommended)"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/account": {
      "delete": {
        "summary": "Delete Account",
        "description": "Permanently delete user account. Requires password verification. Account can be recovered by admin (soft delete).",
        "operationId": "DeleteAccount",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether account deletion was successful"
                    },
                    "message": {
                      "type": "string",
                      "description": "Confirmation message"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "password": {
                    "type": "string",
                    "description": "User's password for verification"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/login": {
      "post": {
        "summary": "Email & Password Login",
        "description": "Authenticate with email and password. Returns JWT tokens for accessing protected endpoints.",
        "operationId": "EmailPasswordLogin",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether login was successful"
                    },
                    "access_token": {
                      "type": "string",
                      "description": "JWT access token (15-minute expiry)"
                    },
                    "refresh_token": {
                      "type": "string",
                      "description": "Refresh token (30-day expiry)"
                    },
                    "expires_in": {
                      "type": "integer",
                      "description": "Access token expiry in seconds (900)"
                    },
                    "token_type": {
                      "type": "string",
                      "description": "Token type (\"Bearer\")"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "Authenticated user's ID"
                    },
                    "email": {
                      "type": "string",
                      "description": "User's email address"
                    },
                    "requires_mfa": {
                      "type": "boolean",
                      "description": "Whether MFA is required (if true, use mfa_session_id)"
                    },
                    "mfa_session_id": {
                      "type": "string",
                      "description": "MFA session ID (if MFA is enabled for this account)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "description": "User's email address"
                  },
                  "password": {
                    "type": "string",
                    "description": "User's password (12+ characters, mixed case, numbers, symbols)"
                  },
                  "device_id": {
                    "type": "string",
                    "description": "Optional device identifier for session tracking"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/whoami": {
      "get": {
        "summary": "Get User Profile",
        "description": "Get the authenticated user's profile information including email, phone, metadata, and verification status.",
        "operationId": "GetUserProfile",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether request was successful"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User's unique identifier (UUID)"
                    },
                    "email": {
                      "type": "string",
                      "description": "User's email address"
                    },
                    "full_name": {
                      "type": "string",
                      "description": "User's full name (from metadata)"
                    },
                    "phone": {
                      "type": "string",
                      "description": "User's phone number (if provided)"
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Account creation timestamp (ISO 8601)"
                    },
                    "email_verified": {
                      "type": "boolean",
                      "description": "Whether email has been verified"
                    },
                    "phone_verified": {
                      "type": "boolean",
                      "description": "Whether phone has been verified"
                    },
                    "metadata": {
                      "type": "object",
                      "description": "Custom user metadata (country, language, preferences, etc.)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      },
      "put": {
        "summary": "Update User Profile",
        "description": "Update the authenticated user's profile information such as name and custom metadata.",
        "operationId": "UpdateUserProfile",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether update was successful"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User's unique identifier"
                    },
                    "email": {
                      "type": "string",
                      "description": "User's email (unchanged)"
                    },
                    "full_name": {
                      "type": "string",
                      "description": "Updated full name"
                    },
                    "metadata": {
                      "type": "object",
                      "description": "Updated metadata (merged with existing)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "full_name": {
                    "type": "string",
                    "description": "User's full name"
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Custom metadata object. Merged with existing metadata."
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/logout": {
      "post": {
        "summary": "Logout",
        "description": "End the current user session and revoke access tokens. User will need to login again.",
        "operationId": "Logout",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether logout was successful"
                    },
                    "message": {
                      "type": "string",
                      "description": "Confirmation message"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/login/magic-link": {
      "post": {
        "summary": "Request Magic Link Login",
        "description": "Send a passwordless magic link to user's email for authentication. No password required - just email access.",
        "operationId": "RequestMagicLinkLogin",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether the request was successful"
                    },
                    "message": {
                      "type": "string",
                      "description": "Human-readable message (always returned for security, even if email doesn't exist)"
                    },
                    "workflow_id": {
                      "type": "string",
                      "description": "Temporal workflow ID for tracking the login flow (only if email exists)"
                    },
                    "email": {
                      "type": "string",
                      "description": "Email address that was submitted"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "description": "User's email address. Must be verified (users who registered via magic link or verified their email)."
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/verify-login": {
      "get": {
        "summary": "Verify Magic Link",
        "description": "Verify magic link token and return JWT authentication tokens. Called automatically when user clicks the magic link.",
        "operationId": "VerifyMagicLink",
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The magic link token (UUID format). Automatically included in the email link."
          },
          {
            "name": "wf",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Workflow ID for correlation. Prevents race conditions. Automatically included in the email link."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether authentication was successful"
                    },
                    "message": {
                      "type": "string",
                      "description": "Human-readable success message"
                    },
                    "access_token": {
                      "type": "string",
                      "description": "JWT access token (15-minute expiry). Use in Authorization header as \"Bearer {token}\""
                    },
                    "refresh_token": {
                      "type": "string",
                      "description": "Opaque refresh token (30-day expiry). Use to get new access tokens"
                    },
                    "expires_in": {
                      "type": "integer",
                      "description": "Access token expiry time in seconds (900 = 15 minutes)"
                    },
                    "token_type": {
                      "type": "string",
                      "description": "Token type, always \"Bearer\""
                    },
                    "user_id": {
                      "type": "string",
                      "description": "Authenticated user's unique identifier (UUID)"
                    },
                    "email": {
                      "type": "string",
                      "description": "User's email address"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/oauth/apple": {
      "get": {
        "summary": "Apple OAuth Login",
        "description": "Initiate Apple Sign In authentication flow. Redirects user to Apple login page.",
        "operationId": "AppleOAuthLogin",
        "parameters": [
          {
            "name": "redirect_uri",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional callback URL. Defaults to configured OAuth callback URL."
          },
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional state parameter for CSRF protection. Auto-generated if not provided."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "auth_url": {
                      "type": "string",
                      "description": "Apple OAuth authorization URL (302 redirect)"
                    },
                    "state": {
                      "type": "string",
                      "description": "CSRF protection token (returned for verification in callback)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/oauth/callback": {
      "get": {
        "summary": "OAuth Callback",
        "description": "OAuth callback endpoint. Handles authorization codes from Google/Apple and returns JWT tokens.",
        "operationId": "OAuthCallback",
        "parameters": [
          {
            "name": "code",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Authorization code from OAuth provider"
          },
          {
            "name": "state",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "CSRF protection token (must match the one sent in the initial request)"
          },
          {
            "name": "error",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Error code if OAuth failed"
          },
          {
            "name": "error_description",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Human-readable error description"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether OAuth authentication was successful"
                    },
                    "access_token": {
                      "type": "string",
                      "description": "JWT access token (15-minute expiry)"
                    },
                    "refresh_token": {
                      "type": "string",
                      "description": "Refresh token (30-day expiry)"
                    },
                    "expires_in": {
                      "type": "integer",
                      "description": "Access token expiry in seconds (900)"
                    },
                    "token_type": {
                      "type": "string",
                      "description": "Token type (\"Bearer\")"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User's unique identifier (UUID)"
                    },
                    "email": {
                      "type": "string",
                      "description": "User's email address from OAuth provider"
                    },
                    "is_new_user": {
                      "type": "boolean",
                      "description": "Whether this is a newly created account"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/oauth/google": {
      "get": {
        "summary": "Google OAuth Login",
        "description": "Initiate Google OAuth authentication flow. Redirects user to Google login page.",
        "operationId": "GoogleOAuthLogin",
        "parameters": [
          {
            "name": "redirect_uri",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional callback URL. Defaults to configured OAuth callback URL."
          },
          {
            "name": "state",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional state parameter for CSRF protection. Auto-generated if not provided."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "auth_url": {
                      "type": "string",
                      "description": "Google OAuth authorization URL (302 redirect)"
                    },
                    "state": {
                      "type": "string",
                      "description": "CSRF protection token (returned for verification in callback)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/refresh": {
      "post": {
        "summary": "Refresh Access Token",
        "description": "Get a new access token using a refresh token. Use this before the access token expires.",
        "operationId": "RefreshAccessToken",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether token refresh was successful"
                    },
                    "access_token": {
                      "type": "string",
                      "description": "New JWT access token (15-minute expiry)"
                    },
                    "expires_in": {
                      "type": "integer",
                      "description": "Token expiry in seconds (900)"
                    },
                    "token_type": {
                      "type": "string",
                      "description": "Token type (\"Bearer\")"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "refresh_token": {
                    "type": "string",
                    "description": "The refresh token received during login or registration"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/register": {
      "post": {
        "summary": "Register User",
        "description": "Register a new user account with email verification. User receives verification link via email.",
        "operationId": "RegisterUser",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether registration was initiated successfully"
                    },
                    "message": {
                      "type": "string",
                      "description": "Human-readable message"
                    },
                    "workflow_id": {
                      "type": "string",
                      "description": "Temporal workflow ID for tracking registration"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "Newly created user ID"
                    },
                    "email": {
                      "type": "string",
                      "description": "Registered email address"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "email": {
                    "type": "string",
                    "description": "User's email address. Must be unique and valid format."
                  },
                  "full_name": {
                    "type": "string",
                    "description": "User's full name (optional but recommended)"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/auth/verify-email": {
      "get": {
        "summary": "Verify Email",
        "description": "Verify user's email address using token from verification email. Called automatically when user clicks verification link.",
        "operationId": "VerifyEmail",
        "parameters": [
          {
            "name": "token",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Email verification token from the verification email"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether verification was successful"
                    },
                    "message": {
                      "type": "string",
                      "description": "Human-readable message"
                    },
                    "access_token": {
                      "type": "string",
                      "description": "JWT access token (user is automatically logged in)"
                    },
                    "refresh_token": {
                      "type": "string",
                      "description": "Refresh token for getting new access tokens"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "auth"
        ]
      }
    },
    "/bookings/availability-slots": {
      "post": {
        "summary": "Get available booking slots",
        "description": "Get available time slots for booking services with a provider. Public endpoint (no authentication required). Returns slots based on provider availability, existing bookings, and time-off periods. **10-50x faster than legacy RPC implementation.**",
        "operationId": "GetAvailabilitySlots",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "provider_id",
                  "date"
                ],
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Provider's unique ID"
                  },
                  "service_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "description": "Array of service IDs to book (recommended)"
                  },
                  "service_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Single service ID (legacy - use service_ids instead)"
                  },
                  "date": {
                    "type": "string",
                    "format": "date",
                    "description": "Date in provider's local timezone (YYYY-MM-DD)",
                    "example": "2026-10-20"
                  },
                  "customer_location": {
                    "type": "object",
                    "description": "Required for customer-location services",
                    "properties": {
                      "lat": {
                        "type": "number",
                        "minimum": -90,
                        "maximum": 90,
                        "description": "Latitude"
                      },
                      "lng": {
                        "type": "number",
                        "minimum": -180,
                        "maximum": 180,
                        "description": "Longitude"
                      }
                    }
                  },
                  "slot_step_minutes": {
                    "type": "integer",
                    "default": 30,
                    "description": "Slot interval in minutes"
                  },
                  "anonymous_id": {
                    "type": "string",
                    "description": "Anonymous user ID for analytics tracking"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Available slots",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "provider_id": {
                      "type": "string"
                    },
                    "service_ids": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    },
                    "date": {
                      "type": "string"
                    },
                    "provider_timezone": {
                      "type": "string",
                      "description": "IANA timezone (e.g., America/New_York)"
                    },
                    "service_location": {
                      "type": "string",
                      "enum": [
                        "customer",
                        "provider"
                      ]
                    },
                    "total_duration_minutes": {
                      "type": "integer"
                    },
                    "travel_minutes": {
                      "type": "integer"
                    },
                    "provider_location": {
                      "type": "object",
                      "properties": {
                        "lat": {
                          "type": "number"
                        },
                        "lng": {
                          "type": "number"
                        }
                      }
                    },
                    "provider_address": {
                      "type": "string"
                    },
                    "distance_meters": {
                      "type": "integer"
                    },
                    "slots": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "start_time": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Service start time (ISO 8601)"
                          },
                          "end_time": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Service end time (ISO 8601)"
                          },
                          "arrival_time": {
                            "type": "string",
                            "format": "date-time",
                            "description": "Provider arrival time (includes travel for customer-location)"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Provider or service not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "tags": [
          "Bookings"
        ]
      }
    },
    "/bookings": {
      "get": {
        "summary": "List bookings",
        "description": "List all bookings for authenticated user (filtered by role)",
        "operationId": "ListBookings",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 20
            },
            "description": "Max results (default: 20, max: 100)"
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Offset for pagination (default: 0)"
          }
        ],
        "responses": {
          "200": {
            "description": "List of bookings",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Bookings"
        ]
      }
    },
    "/bookings/{id}": {
      "get": {
        "summary": "Get booking details",
        "description": "Retrieve full details for a specific booking",
        "operationId": "GetBooking",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Booking ID (UUID)"
          }
        ],
        "responses": {
          "200": {
            "description": "Booking details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Not authorized to view this booking"
          },
          "404": {
            "description": "Booking not found"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Bookings"
        ]
      }
    },
    "/bookings/{id}/transition": {
      "post": {
        "summary": "Transition booking status",
        "description": "Change booking status with location tracking and authorization",
        "operationId": "TransitionBooking",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Booking ID (UUID)"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "next_status"
                ],
                "properties": {
                  "next_status": {
                    "type": "string",
                    "enum": [
                      "pending",
                      "confirmed",
                      "in_progress",
                      "completed",
                      "cancelled"
                    ]
                  },
                  "reason": {
                    "type": "string"
                  },
                  "user_location": {
                    "type": "object",
                    "properties": {
                      "lat": {
                        "type": "number"
                      },
                      "lng": {
                        "type": "number"
                      }
                    }
                  },
                  "provider_location": {
                    "type": "object",
                    "properties": {
                      "lat": {
                        "type": "number"
                      },
                      "lng": {
                        "type": "number"
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transition successful"
          },
          "400": {
            "description": "Invalid request or location"
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Not authorized (permission denied)"
          },
          "404": {
            "description": "Booking not found"
          },
          "409": {
            "description": "Invalid transition"
          },
          "502": {
            "description": "Refund failed"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Bookings"
        ]
      }
    },
    "/bookings/{id}/events": {
      "get": {
        "summary": "Get booking audit trail",
        "description": "Retrieve all status transition events for a booking",
        "operationId": "GetBookingEvents",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Booking ID (UUID)"
          }
        ],
        "responses": {
          "200": {
            "description": "List of audit events",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object"
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Not authorized to view this booking"
          },
          "404": {
            "description": "Booking not found"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Bookings"
        ]
      }
    },
    "/bookings/{id}/status": {
      "get": {
        "summary": "Get booking status",
        "description": "Lightweight endpoint to check current booking status (optimized for polling)",
        "operationId": "GetBookingStatus",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Booking ID (UUID)"
          }
        ],
        "responses": {
          "200": {
            "description": "Current status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "booking_id": {
                      "type": "string"
                    },
                    "status": {
                      "type": "string"
                    },
                    "updated_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "403": {
            "description": "Not authorized to view this booking"
          },
          "404": {
            "description": "Booking not found"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Bookings"
        ]
      }
    },
    "/bookings/reservations": {
      "post": {
        "summary": "Create booking reservation",
        "description": "Create a new booking reservation with instant expiry and race condition handling. Replaces Edge Function with Go API for 2-4x faster performance. First to pay wins approach.",
        "operationId": "CreateReservation",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "provider_id",
                  "service_ids",
                  "reservation_window",
                  "cart_id"
                ],
                "properties": {
                  "provider_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Provider (business) ID"
                  },
                  "service_ids": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "minItems": 1,
                    "description": "List of service IDs to reserve"
                  },
                  "reservation_window": {
                    "type": "object",
                    "required": [
                      "start",
                      "end"
                    ],
                    "properties": {
                      "start": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Service start time (ISO 8601)"
                      },
                      "end": {
                        "type": "string",
                        "format": "date-time",
                        "description": "Service end time (ISO 8601)"
                      }
                    },
                    "description": "Time window when service will be performed"
                  },
                  "cart_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Cart ID containing the services"
                  },
                  "service_location": {
                    "type": "string",
                    "enum": [
                      "provider",
                      "customer"
                    ],
                    "description": "Where service will be performed"
                  },
                  "user_location": {
                    "type": "object",
                    "properties": {
                      "latitude": {
                        "type": "number",
                        "format": "double"
                      },
                      "longitude": {
                        "type": "number",
                        "format": "double"
                      }
                    },
                    "description": "Customer location (if service_location is 'customer')"
                  },
                  "provider_location": {
                    "type": "object",
                    "properties": {
                      "latitude": {
                        "type": "number",
                        "format": "double"
                      },
                      "longitude": {
                        "type": "number",
                        "format": "double"
                      }
                    },
                    "description": "Provider location (if service_location is 'provider')"
                  },
                  "metadata": {
                    "type": "object",
                    "additionalProperties": true,
                    "description": "Optional metadata"
                  },
                  "coupon_code": {
                    "type": "string",
                    "description": "Optional coupon code"
                  },
                  "parent_reservation_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Parent reservation ID (for recurring bookings)"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Reservation created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "reservation_id": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Unique reservation identifier"
                    },
                    "customer_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "provider_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "reservation_window": {
                      "type": "object",
                      "properties": {
                        "start": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "end": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time",
                      "description": "When reservation expires (~1 second = instant expiry)"
                    },
                    "cart_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "service_ids": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "format": "uuid"
                      }
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "active",
                        "converted",
                        "expired"
                      ],
                      "description": "Reservation status"
                    },
                    "blockable": {
                      "type": "boolean",
                      "description": "Whether this reservation blocks the time slot"
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request - invalid input",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "provider_id is required"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid JWT token"
          },
          "409": {
            "description": "Conflict - time slot already taken by another customer",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "Slot no longer available"
                    },
                    "details": {
                      "type": "string",
                      "example": "This time slot is no longer available. Please select a different time."
                    },
                    "provider_id": {
                      "type": "string",
                      "format": "uuid"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Bookings",
          "Reservations"
        ]
      }
    },
    "/bookings/reservations/{id}": {
      "get": {
        "summary": "Get reservation details",
        "description": "Retrieve a reservation by ID with all associated services. User can only access their own reservations.",
        "operationId": "GetReservation",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Reservation ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Reservation details",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "reservation_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "customer_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "provider_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "reservation_window": {
                      "type": "object",
                      "properties": {
                        "start": {
                          "type": "string",
                          "format": "date-time"
                        },
                        "end": {
                          "type": "string",
                          "format": "date-time"
                        }
                      }
                    },
                    "expires_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "cart_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "status": {
                      "type": "string",
                      "enum": [
                        "active",
                        "converted",
                        "expired"
                      ]
                    },
                    "service_ids": {
                      "type": "array",
                      "items": {
                        "type": "string",
                        "format": "uuid"
                      },
                      "description": "List of services in this reservation"
                    },
                    "metadata": {
                      "type": "object",
                      "additionalProperties": true
                    },
                    "coupon_code": {
                      "type": "string"
                    },
                    "booking_id": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Booking ID if reservation was converted"
                    },
                    "parent_reservation_id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "blockable": {
                      "type": "boolean"
                    },
                    "created_at": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized - missing or invalid JWT token"
          },
          "403": {
            "description": "Forbidden - reservation belongs to another user",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "Forbidden - You do not have access to this reservation"
                    }
                  }
                }
              }
            }
          },
          "404": {
            "description": "Reservation not found",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "error": {
                      "type": "string",
                      "example": "Reservation not found"
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal server error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Bookings",
          "Reservations"
        ]
      }
    },
    "/devices/register": {
      "post": {
        "summary": "Register Device",
        "description": "Register a new IoT device, OBD-II adapter, or mobile device with the Bookovia telematics platform for fleet tracking and monitoring",
        "operationId": "RegisterDevice",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "devices"
        ]
      }
    },
    "/devices/{device_id}/settings": {
      "put": {
        "summary": "Device Settings",
        "description": "Configure device parameters, telemetry collection settings, and operational behaviors for optimal fleet management and data collection",
        "operationId": "DeviceSettings",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "devices"
        ]
      }
    },
    "/devices/{device_id}/status": {
      "get": {
        "summary": "Device Status",
        "description": "Monitor real-time device connectivity, health status, and operational metrics for fleet management and troubleshooting",
        "operationId": "DeviceStatus",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "devices"
        ]
      }
    },
    "/directory/cities/{state}/{city}": {
      "get": {
        "summary": "City Directory",
        "description": "Get comprehensive directory for a specific city including paginated provider listings, service categories, and nearby areas.",
        "operationId": "CityDirectory",
        "parameters": [
          {
            "name": "state",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Two-letter state code (e.g., \"CA\", \"TX\", \"NY\")"
          },
          {
            "name": "city",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "City name (URL-encoded if contains spaces)"
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Page number for pagination (min: 1)"
          },
          {
            "name": "page_size",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Number of providers per page (min: 1, max: 100)"
          },
          {
            "name": "lat",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "User latitude for distance calculation (optional)"
          },
          {
            "name": "lon",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "User longitude for distance calculation (optional)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "city": {
                      "type": "string",
                      "description": "City"
                    },
                    "state": {
                      "type": "string",
                      "description": "Full state name"
                    },
                    "state_code": {
                      "type": "string",
                      "description": "State code"
                    },
                    "total_providers": {
                      "type": "integer",
                      "description": "Total number of providers in this city"
                    },
                    "average_rating": {
                      "type": "number",
                      "description": "Average provider rating (0-5), null if no ratings"
                    },
                    "average_cost": {
                      "type": "number",
                      "description": "Average service cost in USD"
                    },
                    "providers": {
                      "type": "array",
                      "description": "Paginated list of providers\n  \n  \n    Provider unique identifier"
                    },
                    "name": {
                      "type": "string",
                      "description": "Provider business name"
                    },
                    "address": {
                      "type": "string",
                      "description": "Street address"
                    },
                    "zip_code": {
                      "type": "string",
                      "description": "ZIP code"
                    },
                    "phone": {
                      "type": "string",
                      "description": "Phone number"
                    },
                    "rating": {
                      "type": "number",
                      "description": "Average rating (0-5)"
                    },
                    "review_count": {
                      "type": "integer",
                      "description": "Number of reviews"
                    },
                    "verified": {
                      "type": "boolean",
                      "description": "Whether provider is verified"
                    },
                    "ev_charging_available": {
                      "type": "boolean",
                      "description": "EV charging available"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Distance from user location in kilometers (only if lat/lon provided)"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Provider latitude"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Provider longitude"
                    },
                    "service_categories": {
                      "type": "array",
                      "description": "Service category statistics for this city\n  \n  \n    Service category name"
                    },
                    "provider_count": {
                      "type": "integer",
                      "description": "Number of providers offering this category"
                    },
                    "growth_rate": {
                      "type": "number",
                      "description": "Category growth rate percentage"
                    },
                    "nearby_areas": {
                      "type": "array",
                      "description": "List of nearby cities/areas with providers"
                    },
                    "pagination": {
                      "type": "object",
                      "description": "Pagination metadata\n  \n  \n    Current page number"
                    },
                    "page_size": {
                      "type": "integer",
                      "description": "Items per page"
                    },
                    "total_pages": {
                      "type": "integer",
                      "description": "Total number of pages"
                    },
                    "total_items": {
                      "type": "integer",
                      "description": "Total number of providers"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "directory"
        ]
      }
    },
    "/directory/providers/{id}": {
      "get": {
        "summary": "Provider Detail",
        "description": "Get comprehensive details for a specific service provider including services, operating hours, reviews, and nearby alternatives.",
        "operationId": "ProviderDetail",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Provider unique identifier (e.g., \"prov_abc123\")"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "provider": {
                      "type": "object",
                      "description": "Complete provider profile\n  \n  \n    Provider unique identifier"
                    },
                    "name": {
                      "type": "string",
                      "description": "Provider name"
                    },
                    "description": {
                      "type": "string",
                      "description": "Service description"
                    },
                    "address": {
                      "type": "string",
                      "description": "Street address"
                    },
                    "city": {
                      "type": "string",
                      "description": "City"
                    },
                    "state_code": {
                      "type": "string",
                      "description": "State code"
                    },
                    "zip_code": {
                      "type": "string",
                      "description": "ZIP code"
                    },
                    "phone": {
                      "type": "string",
                      "description": "Phone number"
                    },
                    "email": {
                      "type": "string",
                      "description": "Email address"
                    },
                    "website": {
                      "type": "string",
                      "description": "Website URL"
                    },
                    "rating": {
                      "type": "number",
                      "description": "Average rating"
                    },
                    "review_count": {
                      "type": "integer",
                      "description": "Total number of reviews"
                    },
                    "verified": {
                      "type": "boolean",
                      "description": "Whether provider is verified"
                    },
                    "ev_charging_available": {
                      "type": "boolean",
                      "description": "EV charging available"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Location latitude"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Location longitude"
                    },
                    "services": {
                      "type": "array",
                      "description": "Services offered by this provider\n  \n  \n    Service unique identifier"
                    },
                    "service_name": {
                      "type": "string",
                      "description": "Name of the service"
                    },
                    "price": {
                      "type": "number",
                      "description": "Service price in USD (null if varies)"
                    },
                    "duration_minutes": {
                      "type": "integer",
                      "description": "Estimated service duration"
                    },
                    "category": {
                      "type": "string",
                      "description": "Service category"
                    },
                    "vehicle_brands": {
                      "type": "array",
                      "description": "Vehicle brands serviced\n  \n  \n    Vehicle brand name (e.g., \"Toyota\", \"Ford\")"
                    },
                    "specialization": {
                      "type": "boolean",
                      "description": "Whether this is a specialty brand for this provider"
                    },
                    "operating_hours": {
                      "type": "array",
                      "description": "Weekly operating hours\n  \n  \n    Day of week (0 = Sunday, 6 = Saturday)"
                    },
                    "open_time": {
                      "type": "string",
                      "description": "Opening time (HH:MM format)"
                    },
                    "close_time": {
                      "type": "string",
                      "description": "Closing time (HH:MM format)"
                    },
                    "is_closed": {
                      "type": "boolean",
                      "description": "Whether closed this day"
                    },
                    "reviews": {
                      "type": "array",
                      "description": "Customer reviews\n  \n  \n    Review unique identifier"
                    },
                    "provider_id": {
                      "type": "string",
                      "description": "Provider ID"
                    },
                    "user_name": {
                      "type": "string",
                      "description": "Reviewer name"
                    },
                    "comment": {
                      "type": "string",
                      "description": "Review comment"
                    },
                    "created_at": {
                      "type": "string",
                      "description": "Review timestamp (ISO 8601)"
                    },
                    "nearby_providers": {
                      "type": "array",
                      "description": "Alternative providers in the area\n  \n  \n    Provider ID"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Distance in kilometers"
                    },
                    "service_area": {
                      "type": "array",
                      "description": "Cities/areas serviced by this provider"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "directory"
        ]
      }
    },
    "/directory/search": {
      "get": {
        "summary": "Search Providers",
        "description": "Search for service providers with flexible filters including location, category, rating, verification status, and services offered.",
        "operationId": "SearchProviders",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Search query (searches provider name, description, services)"
          },
          {
            "name": "location",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Location filter (city, state, or \"city, state\")"
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Service category filter (e.g., \"auto_repair\", \"oil_change\", \"ev_charging\")"
          },
          {
            "name": "min_rating",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Minimum provider rating (1-5)"
          },
          {
            "name": "verified",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Filter for verified providers only (true/false)"
          },
          {
            "name": "services",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated list of required services"
          },
          {
            "name": "page",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Page number for pagination (min: 1)"
          },
          {
            "name": "page_size",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Number of results per page (min: 1, max: 100)"
          },
          {
            "name": "lat",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "User latitude for distance calculation (optional)"
          },
          {
            "name": "lon",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "User longitude for distance calculation (optional)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "query": {
                      "type": "string",
                      "description": "Original search query"
                    },
                    "total_results": {
                      "type": "integer",
                      "description": "Total number of matching providers"
                    },
                    "providers": {
                      "type": "array",
                      "description": "Paginated list of matching providers\n  \n  \n    Provider unique identifier"
                    },
                    "name": {
                      "type": "string",
                      "description": "Provider business name"
                    },
                    "description": {
                      "type": "string",
                      "description": "Provider description"
                    },
                    "address": {
                      "type": "string",
                      "description": "Street address"
                    },
                    "city": {
                      "type": "string",
                      "description": "City"
                    },
                    "state_code": {
                      "type": "string",
                      "description": "State code"
                    },
                    "zip_code": {
                      "type": "string",
                      "description": "ZIP code"
                    },
                    "phone": {
                      "type": "string",
                      "description": "Phone number"
                    },
                    "rating": {
                      "type": "number",
                      "description": "Average rating (0-5)"
                    },
                    "review_count": {
                      "type": "integer",
                      "description": "Number of reviews"
                    },
                    "verified": {
                      "type": "boolean",
                      "description": "Verified filter applied"
                    },
                    "ev_charging_available": {
                      "type": "boolean",
                      "description": "EV charging available"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Distance from user location in kilometers (only if lat/lon provided)"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Provider latitude"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Provider longitude"
                    },
                    "filters": {
                      "type": "object",
                      "description": "Applied filters\n  \n  \n    Location filter applied"
                    },
                    "category": {
                      "type": "string",
                      "description": "Category filter applied"
                    },
                    "min_rating": {
                      "type": "integer",
                      "description": "Minimum rating filter applied"
                    },
                    "services": {
                      "type": "array",
                      "description": "Services filters applied"
                    },
                    "pagination": {
                      "type": "object",
                      "description": "Pagination metadata\n  \n  \n    Current page number"
                    },
                    "page_size": {
                      "type": "integer",
                      "description": "Items per page"
                    },
                    "total_pages": {
                      "type": "integer",
                      "description": "Total number of pages"
                    },
                    "total_items": {
                      "type": "integer",
                      "description": "Total number of matching providers"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "directory"
        ]
      }
    },
    "/directory/states/{state}": {
      "get": {
        "summary": "State Directory",
        "description": "Get comprehensive directory statistics for a specific US state including top cities, providers, and service categories.",
        "operationId": "StateDirectory",
        "parameters": [
          {
            "name": "state",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Two-letter state code (e.g., \"CA\", \"TX\", \"NY\")"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "state": {
                      "type": "string",
                      "description": "Full state name"
                    },
                    "state_code": {
                      "type": "string",
                      "description": "Two-letter state code"
                    },
                    "total_providers": {
                      "type": "integer",
                      "description": "Total number of providers in this state"
                    },
                    "total_cities": {
                      "type": "integer",
                      "description": "Number of cities with providers"
                    },
                    "average_rating": {
                      "type": "number",
                      "description": "Average city provider rating"
                    },
                    "ev_ready_coverage": {
                      "type": "number",
                      "description": "Percentage of providers with EV charging capabilities (0-100)"
                    },
                    "top_cities": {
                      "type": "array",
                      "description": "Top cities by provider count\n  \n  \n    City name"
                    },
                    "provider_count": {
                      "type": "integer",
                      "description": "Number of providers offering this category"
                    },
                    "top_service": {
                      "type": "string",
                      "description": "Most popular service in this city"
                    },
                    "service_categories": {
                      "type": "array",
                      "description": "Service category statistics for this state\n  \n  \n    Service category name"
                    },
                    "growth_rate": {
                      "type": "number",
                      "description": "Category growth rate percentage"
                    },
                    "average_service_costs": {
                      "type": "array",
                      "description": "Average costs by service type in this state\n  \n  \n    Name of the service"
                    },
                    "average_cost": {
                      "type": "number",
                      "description": "Average service cost in USD"
                    },
                    "min_cost": {
                      "type": "number",
                      "description": "Minimum cost in USD"
                    },
                    "max_cost": {
                      "type": "number",
                      "description": "Maximum cost in USD"
                    },
                    "top_providers": {
                      "type": "array",
                      "description": "Top-rated providers in this state\n  \n  \n    Provider unique identifier"
                    },
                    "name": {
                      "type": "string",
                      "description": "Provider business name"
                    },
                    "city": {
                      "type": "string",
                      "description": "City location"
                    },
                    "rating": {
                      "type": "number",
                      "description": "Average rating (0-5)"
                    },
                    "review_count": {
                      "type": "integer",
                      "description": "Number of reviews"
                    },
                    "verified": {
                      "type": "boolean",
                      "description": "Whether provider is verified"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "directory"
        ]
      }
    },
    "/directory/usa": {
      "get": {
        "summary": "USA Directory",
        "description": "Get comprehensive USA-wide directory statistics including top states, service categories, and trending searches.",
        "operationId": "USADirectory",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Maximum number of top states to return (min: 1, max: 50)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total_states": {
                      "type": "integer",
                      "description": "Total number of states with providers"
                    },
                    "total_providers": {
                      "type": "integer",
                      "description": "Total number of service providers nationwide"
                    },
                    "total_cities": {
                      "type": "integer",
                      "description": "Total number of cities with providers"
                    },
                    "total_services": {
                      "type": "integer",
                      "description": "Total number of services offered"
                    },
                    "top_states": {
                      "type": "array",
                      "description": "Top states by provider count\n  \n  \n    Full state name"
                    },
                    "state_code": {
                      "type": "string",
                      "description": "Two-letter state code (e.g., \"CA\", \"TX\")"
                    },
                    "provider_count": {
                      "type": "integer",
                      "description": "Number of providers offering this category"
                    },
                    "city_count": {
                      "type": "integer",
                      "description": "Number of cities with providers"
                    },
                    "average_rating": {
                      "type": "number",
                      "description": "Average provider rating (0-5), null if no ratings"
                    },
                    "service_categories": {
                      "type": "array",
                      "description": "Service category statistics\n  \n  \n    Service category name"
                    },
                    "growth_rate": {
                      "type": "number",
                      "description": "Category growth rate percentage"
                    },
                    "average_service_costs": {
                      "type": "array",
                      "description": "Average costs by service type\n  \n  \n    Name of the service"
                    },
                    "average_cost": {
                      "type": "number",
                      "description": "Average service cost in USD"
                    },
                    "min_cost": {
                      "type": "number",
                      "description": "Minimum cost in USD"
                    },
                    "max_cost": {
                      "type": "number",
                      "description": "Maximum cost in USD"
                    },
                    "trending_searches": {
                      "type": "array",
                      "description": "Trending search queries\n  \n  \n    Search query text"
                    },
                    "search_count": {
                      "type": "integer",
                      "description": "Number of searches"
                    },
                    "growth_percent": {
                      "type": "number",
                      "description": "Growth percentage"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "directory"
        ]
      }
    },
    "/emergency/alerts": {
      "post": {
        "summary": "Emergency Alerts",
        "description": "Comprehensive emergency alert and notification system for configuring, managing, and distributing safety alerts across fleet operations",
        "operationId": "EmergencyAlerts",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "emergency"
        ]
      }
    },
    "/emergency/crash-detection": {
      "post": {
        "summary": "Crash Detection",
        "description": "Real-time crash detection and automatic emergency response system with AI-powered collision analysis and emergency services integration",
        "operationId": "CrashDetection",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "emergency"
        ]
      }
    },
    "/emergency/incidents/{incident_id}": {
      "get": {
        "summary": "Emergency Incidents",
        "description": "Comprehensive emergency incident management system for tracking, coordinating, and resolving safety incidents with real-time status updates",
        "operationId": "EmergencyIncidents",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "emergency"
        ]
      }
    },
    "/search": {
      "get": {
        "summary": "Search Addresses",
        "description": "Find addresses using full-text search across 146.7 million US addresses",
        "operationId": "SearchAddresses",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Address search query\n  \n  Examples:\n  - \"1600 Amphitheatre Parkway Mountain View CA\"\n  - \"Empire State Building New York\"\n  - \"Main Street San Francisco\"\n  \n  Supports partial addresses and fuzzy matc"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Maximum number of results (1 to 100)\n  \n  Default: 10"
          },
          {
            "name": "country",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by country code (e.g., \"US\")\n  \n  Currently only US addresses are indexed"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "count": {
                      "type": "integer",
                      "description": "Number of addresses returned"
                    },
                    "results": {
                      "type": "array",
                      "description": "Array of address results sorted by relevance\n  \n  \n    \n      Unique address identifier (GERS ID)"
                    },
                    "address": {
                      "type": "string",
                      "description": "Formatted address string"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Address latitude coordinate"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Address longitude coordinate"
                    },
                    "confidence": {
                      "type": "number",
                      "description": "Match confidence score (0.0 to 1.0, higher is better)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/autocomplete": {
      "get": {
        "summary": "Address Autocomplete",
        "description": "Get real-time address suggestions as users type with sub-50ms response time",
        "operationId": "AddressAutocomplete",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Partial address string (minimum 3 characters recommended)\n  \n  Examples:\n  - \"1600 Amp\"\n  - \"Main Street\"\n  - \"94043\""
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Maximum number of suggestions (1 to 20)\n  \n  Default: 5\n  \n  Keep low (5-10) for best performance"
          },
          {
            "name": "lat",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Optional latitude for proximity bias (not implemented in current version)\n  \n  Future enhancement: bias results toward this location"
          },
          {
            "name": "lon",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Optional longitude for proximity bias (not implemented in current version)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "suggestions": {
                      "type": "array",
                      "description": "Array of address suggestions sorted by relevance\n  \n  \n    \n      Suggested address text for display"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Address latitude coordinate"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Address longitude coordinate"
                    },
                    "id": {
                      "type": "string",
                      "description": "Unique address identifier (GERS ID)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/boundaries/lookup": {
      "get": {
        "summary": "Lookup Boundaries",
        "description": "Get administrative boundaries (city, county, state, country) for any coordinate",
        "operationId": "LookupBoundaries",
        "parameters": [
          {
            "name": "lat",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Latitude coordinate (-90 to 90)"
          },
          {
            "name": "lon",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Longitude coordinate (-180 to 180)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "boundaries": {
                      "type": "object",
                      "description": "Hierarchical boundary information\n  \n  \n    \n      City, town, or locality name"
                    },
                    "county": {
                      "type": "string",
                      "description": "County or equivalent administrative division"
                    },
                    "state": {
                      "type": "string",
                      "description": "State, province, or region full name"
                    },
                    "state_code": {
                      "type": "string",
                      "description": "ISO 3166-2 subdivision code (e.g., \"US-NY\" for New York)"
                    },
                    "country": {
                      "type": "string",
                      "description": "Country full name"
                    },
                    "country_code": {
                      "type": "string",
                      "description": "ISO 3166-1 alpha-2 country code (e.g., \"US\")"
                    },
                    "region": {
                      "type": "string",
                      "description": "Region code (same as state_code)"
                    },
                    "h3_cell": {
                      "type": "string",
                      "description": "H3 cell at resolution 7 for this coordinate"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/h3": {
      "get": {
        "summary": "H3 Utility",
        "description": "Convert between geographic coordinates and H3 hexagonal spatial indexes",
        "operationId": "H3Utility",
        "parameters": [
          {
            "name": "lat",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Latitude coordinate (-90 to 90)\n  \n  Required for coordinate → H3 conversion"
          },
          {
            "name": "lon",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Longitude coordinate (-180 to 180)\n  \n  Required for coordinate → H3 conversion"
          },
          {
            "name": "resolution",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "H3 resolution level (0 to 15)\n  \n  - Resolution 7: ~5km cells (admin boundaries)\n  - Resolution 11: ~25m cells (places, addresses)\n  - Resolution 15: ~1m cells (high precision)\n  \n  Default: 11"
          },
          {
            "name": "h3",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "H3 cell identifier (e.g., \"8928308280fffff\")\n  \n  Required for H3 → coordinate conversion"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "h3_cell": {
                      "type": "string",
                      "description": "H3 cell identifier (15-character hexadecimal string)"
                    },
                    "resolution": {
                      "type": "integer",
                      "description": "H3 resolution level (0-15)"
                    },
                    "centroid": {
                      "type": "object",
                      "description": "Center coordinates of the H3 cell\n  \n  \n    \n      Cell center latitude"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Cell center longitude"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/places/details": {
      "get": {
        "summary": "Get Place Details",
        "description": "Get comprehensive information about a specific place by its unique identifier",
        "operationId": "GetPlaceDetails",
        "parameters": [
          {
            "name": "id",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Place identifier (Overture GERS ID)\n  \n  Obtained from Places Search or Places Nearby responses"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "place": {
                      "type": "object",
                      "description": "Complete place information\n  \n  \n    \n      Unique place identifier (GERS ID)"
                    },
                    "name": {
                      "type": "string",
                      "description": "Place name"
                    },
                    "category": {
                      "type": "string",
                      "description": "Primary category"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Latitude coordinate"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Longitude coordinate"
                    },
                    "address": {
                      "type": "string",
                      "description": "Formatted street address (if available)"
                    },
                    "brand": {
                      "type": "string",
                      "description": "Brand name for chain locations (if available)"
                    },
                    "h3_cell": {
                      "type": "string",
                      "description": "H3 cell identifier at resolution 11 (if available)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/places/nearby": {
      "get": {
        "summary": "Find Nearby Places",
        "description": "Find points of interest within a specified radius of a location",
        "operationId": "FindNearbyPlaces",
        "parameters": [
          {
            "name": "lat",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Center point latitude (-90 to 90)"
          },
          {
            "name": "lon",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Center point longitude (-180 to 180)"
          },
          {
            "name": "radius",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Search radius in kilometers (0.1 to 10)\n  \n  Maximum 10km for optimal performance"
          },
          {
            "name": "categories",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by category (e.g., \"restaurant\", \"hotel\", \"gas_station\")"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Maximum number of results (1 to 100)\n  \n  Default: 20"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "count": {
                      "type": "integer",
                      "description": "Number of places found within radius"
                    },
                    "places": {
                      "type": "array",
                      "description": "Array of places sorted by distance (nearest first)\n  \n  \n    \n      Unique place identifier (GERS ID)"
                    },
                    "name": {
                      "type": "string",
                      "description": "Place name"
                    },
                    "category": {
                      "type": "string",
                      "description": "Primary category"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Place latitude"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Place longitude"
                    },
                    "address": {
                      "type": "string",
                      "description": "Formatted address (if available)"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Distance from center point in kilometers (rounded to 2 decimals)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/places/search": {
      "get": {
        "summary": "Search Places",
        "description": "Search for places, businesses, and points of interest by name, category, or keyword",
        "operationId": "SearchPlaces",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Search query text (e.g., \"starbucks\", \"pizza near me\", \"hotels\")\n  \n  Supports fuzzy matching and partial text search"
          },
          {
            "name": "lat",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Center point latitude for spatial ranking (-90 to 90)\n  \n  When provided with `lon`, results are sorted by relevance and proximity"
          },
          {
            "name": "lon",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Center point longitude for spatial ranking (-180 to 180)\n  \n  Required if `lat` is provided"
          },
          {
            "name": "radius",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Search radius in kilometers (0.1 to 100)\n  \n  Only returns results within this distance from center point\n  \n  Default: 50"
          },
          {
            "name": "categories",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by category (e.g., \"restaurant\", \"coffee_shop\", \"hotel\")\n  \n  Multiple categories not supported (use separate requests)"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Maximum number of results to return (1 to 100)\n  \n  Default: 20"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "count": {
                      "type": "integer",
                      "description": "Number of places returned in this response"
                    },
                    "places": {
                      "type": "array",
                      "description": "Array of place objects matching the search criteria\n  \n  \n    \n      Unique place identifier (Overture GERS ID)"
                    },
                    "name": {
                      "type": "string",
                      "description": "Place name (e.g., \"Starbucks\", \"Central Park\")"
                    },
                    "category": {
                      "type": "string",
                      "description": "Primary category (e.g., \"coffee_shop\", \"restaurant\", \"hotel\")"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Place latitude coordinate"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Place longitude coordinate"
                    },
                    "address": {
                      "type": "string",
                      "description": "Formatted street address (if available)"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Distance from search center point in kilometers (only if lat/lon provided)"
                    },
                    "confidence": {
                      "type": "number",
                      "description": "Search relevance score (0.0 to 1.0, higher is better match)"
                    },
                    "error": {
                      "type": "string",
                      "description": "Error message if the request failed"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/timezone": {
      "get": {
        "summary": "Get Timezone",
        "description": "Determine the timezone for any geographic coordinate",
        "operationId": "GetTimezone",
        "parameters": [
          {
            "name": "lat",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Latitude coordinate (-90 to 90)"
          },
          {
            "name": "lon",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Longitude coordinate (-180 to 180)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "timezone": {
                      "type": "string",
                      "description": "IANA timezone identifier (e.g., \"America/New_York\", \"America/Los_Angeles\")\n  \n  Can be used with standard datetime libraries for conversions"
                    },
                    "region": {
                      "type": "string",
                      "description": "ISO 3166-2 region code used for timezone lookup (e.g., \"US-NY\")"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/validate": {
      "get": {
        "summary": "Validate Address",
        "description": "Check if an address exists in the database with a simple boolean response",
        "operationId": "ValidateAddress",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Address string to validate\n  \n  Should be a reasonably complete address for accurate validation"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "exists": {
                      "type": "boolean",
                      "description": "True if address exists with confidence &gt;0.7, false otherwise"
                    },
                    "id": {
                      "type": "string",
                      "description": "Address identifier (only present if exists = true)"
                    },
                    "address": {
                      "type": "string",
                      "description": "Standardized address text (only present if exists = true)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "geocoding"
        ]
      }
    },
    "/locations/batch": {
      "post": {
        "summary": "Batch Upload Locations",
        "description": "Upload multiple location points in a single request for active trips with optimized processing",
        "operationId": "BatchUploadLocations",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the trip that received the location updates"
                    },
                    "processed_count": {
                      "type": "integer",
                      "description": "Number of location points successfully processed"
                    },
                    "rejected_count": {
                      "type": "integer",
                      "description": "Number of location points that were rejected due to validation errors"
                    },
                    "events_detected": {
                      "type": "array",
                      "description": "Array of safety events detected from the uploaded location data\n  \n  \n    \n      Type of event detected: \"harsh_braking\", \"harsh_acceleration\", \"harsh_cornering\", \"speeding\""
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "When the event occurred"
                    },
                    "severity": {
                      "type": "string",
                      "description": "Event severity: \"low\", \"moderate\", \"high\""
                    },
                    "location": {
                      "type": "object",
                      "description": "GPS coordinates where the event occurred"
                    },
                    "trip_analytics": {
                      "type": "object",
                      "description": "Updated real-time trip analytics\n  \n  \n    \n      Current total distance for the trip"
                    },
                    "current_duration_minutes": {
                      "type": "number",
                      "description": "Current trip duration"
                    },
                    "current_safety_score": {
                      "type": "integer",
                      "description": "Real-time safety score"
                    },
                    "last_location": {
                      "type": "object",
                      "description": "Most recent location point"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "trip_id": {
                    "type": "string",
                    "description": "Unique identifier for the active trip to upload locations to"
                  },
                  "locations": {
                    "type": "array",
                    "description": "Array of location data points to upload\n  \n  \n    \n      Latitude coordinate in decimal degrees (-90 to 90)"
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Longitude coordinate in decimal degrees (-180 to 180)"
                  },
                  "timestamp": {
                    "type": "string",
                    "description": "ISO 8601 timestamp when the location was recorded"
                  },
                  "speed_kmh": {
                    "type": "number",
                    "description": "Vehicle speed in kilometers per hour"
                  },
                  "heading": {
                    "type": "number",
                    "description": "Direction of travel in degrees (0-360, where 0 is North)"
                  },
                  "accuracy_meters": {
                    "type": "number",
                    "description": "GPS accuracy in meters"
                  },
                  "altitude_meters": {
                    "type": "number",
                    "description": "Altitude above sea level in meters"
                  },
                  "battery_level": {
                    "type": "number",
                    "description": "Device battery level percentage (0-100)"
                  },
                  "network_type": {
                    "type": "string",
                    "description": "Network connection type: \"wifi\", \"cellular\", \"offline\""
                  },
                  "device_info": {
                    "type": "object",
                    "description": "Device information for this batch of locations\n  \n  \n    \n      Unique device identifier"
                  },
                  "device_model": {
                    "type": "string",
                    "description": "Device model information"
                  },
                  "os_version": {
                    "type": "string",
                    "description": "Operating system version"
                  },
                  "app_version": {
                    "type": "string",
                    "description": "Application version that recorded the data"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "locations"
        ]
      }
    },
    "/trips/{trip_id}/route": {
      "get": {
        "summary": "Get Route Data",
        "description": "Retrieve detailed route information including path optimization, traffic analysis, and efficiency metrics",
        "operationId": "GetRouteData",
        "parameters": [
          {
            "name": "trip_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique identifier for the trip to retrieve route data for"
          },
          {
            "name": "include_waypoints",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include detailed waypoint information in the response"
          },
          {
            "name": "include_traffic_data",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include historical traffic data for the route"
          },
          {
            "name": "include_alternatives",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include analysis of alternative routes and their efficiency"
          },
          {
            "name": "simplify_geometry",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to simplify the route geometry for reduced payload size"
          },
          {
            "name": "geometry_precision",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Number of decimal places for coordinate precision (1-8)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the trip"
                    },
                    "route_status": {
                      "type": "string",
                      "description": "Route processing status: \"active\", \"completed\", \"analyzing\""
                    },
                    "route_geometry": {
                      "type": "object",
                      "description": "Detailed route path information\n  \n  \n    \n      GeoJSON geometry type (typically \"LineString\")"
                    },
                    "coordinates": {
                      "type": "array",
                      "description": "Array of [longitude, latitude] coordinate pairs defining the route path"
                    },
                    "total_points": {
                      "type": "integer",
                      "description": "Total number of coordinate points in the full route"
                    },
                    "simplified": {
                      "type": "boolean",
                      "description": "Whether the geometry has been simplified for transmission"
                    },
                    "route_analytics": {
                      "type": "object",
                      "description": "Route performance and efficiency metrics\n  \n  \n    \n      Total route distance in kilometers"
                    },
                    "estimated_duration_minutes": {
                      "type": "number",
                      "description": "Estimated travel time based on speed limits and traffic"
                    },
                    "actual_duration_minutes": {
                      "type": "number",
                      "description": "Actual travel time (null for active trips)"
                    },
                    "efficiency_score": {
                      "type": "integer",
                      "description": "Route efficiency score (0-100)"
                    },
                    "deviation_percentage": {
                      "type": "number",
                      "description": "Percentage deviation from optimal route"
                    },
                    "fuel_efficiency_rating": {
                      "type": "string",
                      "description": "Fuel efficiency rating: \"excellent\", \"good\", \"average\", \"poor\""
                    },
                    "waypoints": {
                      "type": "array",
                      "description": "Significant waypoints along the route (if include_waypoints=true)\n  \n  \n    \n      Unique identifier for the waypoint"
                    },
                    "latitude": {
                      "type": "number",
                      "description": "Waypoint latitude coordinate"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Waypoint longitude coordinate"
                    },
                    "waypoint_type": {
                      "type": "string",
                      "description": "Type of waypoint: \"start\", \"end\", \"stop\", \"turn\", \"landmark\""
                    },
                    "distance_from_start_km": {
                      "type": "number",
                      "description": "Distance from route start in kilometers"
                    },
                    "estimated_arrival_time": {
                      "type": "string",
                      "description": "Estimated arrival time at this waypoint"
                    },
                    "traffic_analysis": {
                      "type": "object",
                      "description": "Traffic conditions analysis (if include_traffic_data=true)\n  \n  \n    \n      Overall traffic congestion: \"free_flow\", \"light\", \"moderate\", \"heavy\", \"standstill\""
                    },
                    "traffic_delay_minutes": {
                      "type": "number",
                      "description": "Additional time due to traffic conditions"
                    },
                    "congested_segments": {
                      "type": "array",
                      "description": "Route segments with significant traffic"
                    },
                    "peak_hours_impact": {
                      "type": "object",
                      "description": "Analysis of peak hour traffic impact"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "locations"
        ]
      }
    },
    "/locations/nearby": {
      "get": {
        "summary": "Find Nearby Locations",
        "description": "Find points of interest, services, and amenities near a specific location or along a route",
        "operationId": "FindNearbyLocations",
        "parameters": [
          {
            "name": "latitude",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Latitude coordinate for the search center (-90 to 90)"
          },
          {
            "name": "longitude",
            "in": "query",
            "required": true,
            "schema": {
              "type": "number"
            },
            "description": "Longitude coordinate for the search center (-180 to 180)"
          },
          {
            "name": "radius_km",
            "in": "query",
            "required": false,
            "schema": {
              "type": "number"
            },
            "description": "Search radius in kilometers (0.1 to 50)"
          },
          {
            "name": "category",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by category. Options: \"fuel\", \"parking\", \"food\", \"lodging\", \"medical\", \"repair\", \"rest_area\", \"charging\", \"truck_stop\""
          },
          {
            "name": "subcategory",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Further filter by subcategory (depends on category)"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Maximum number of results to return (1 to 100)"
          },
          {
            "name": "include_availability",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include real-time availability information"
          },
          {
            "name": "include_pricing",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include pricing information (where available)"
          },
          {
            "name": "vehicle_type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Vehicle type for relevant filtering: \"car\", \"truck\", \"motorcycle\", \"van\", \"bus\""
          },
          {
            "name": "route_trip_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Optional trip ID to find locations along the route instead of radius search"
          },
          {
            "name": "sort_by",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Sort results by: \"distance\", \"rating\", \"availability\", \"price\""
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "search_center": {
                      "type": "object",
                      "description": "The coordinates used as the search center\n  \n  \n    \n      Search center latitude"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Search center longitude"
                    },
                    "radius_km": {
                      "type": "number",
                      "description": "Search radius used"
                    },
                    "locations": {
                      "type": "array",
                      "description": "Array of nearby locations matching the search criteria\n  \n  \n    \n      Unique identifier for the location"
                    },
                    "name": {
                      "type": "string",
                      "description": "Business or location name"
                    },
                    "category": {
                      "type": "string",
                      "description": "Primary category of the location"
                    },
                    "subcategory": {
                      "type": "string",
                      "description": "Specific subcategory"
                    },
                    "coordinates": {
                      "type": "object",
                      "description": "Location coordinates and address"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Distance from search center in kilometers"
                    },
                    "rating": {
                      "type": "number",
                      "description": "Average user rating (0.0 to 5.0)"
                    },
                    "availability": {
                      "type": "object",
                      "description": "Real-time availability information"
                    },
                    "services": {
                      "type": "array",
                      "description": "Available services and amenities"
                    },
                    "contact_info": {
                      "type": "object",
                      "description": "Contact and hours information"
                    },
                    "search_metadata": {
                      "type": "object",
                      "description": "Metadata about the search results\n  \n  \n    \n      Total number of locations found within radius"
                    },
                    "returned_count": {
                      "type": "integer",
                      "description": "Number of locations returned in this response"
                    },
                    "search_time_ms": {
                      "type": "integer",
                      "description": "Time taken to process the search"
                    },
                    "data_freshness": {
                      "type": "string",
                      "description": "Freshness of the location data"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "locations"
        ]
      }
    },
    "/locations/single": {
      "post": {
        "summary": "Upload Single Location",
        "description": "Upload a single GPS location point with immediate processing and real-time event detection",
        "operationId": "UploadSingleLocation",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the trip that received the location update"
                    },
                    "location_id": {
                      "type": "string",
                      "description": "Unique identifier for the uploaded location point"
                    },
                    "processed_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the location was processed"
                    },
                    "events_detected": {
                      "type": "array",
                      "description": "Array of safety events detected from this location update\n  \n  \n    \n      Unique identifier for the detected event"
                    },
                    "event_type": {
                      "type": "string",
                      "description": "Type of event: \"harsh_braking\", \"harsh_acceleration\", \"harsh_cornering\", \"speeding\", \"rapid_direction_change\""
                    },
                    "severity": {
                      "type": "string",
                      "description": "Event severity: \"low\", \"moderate\", \"high\", \"critical\""
                    },
                    "confidence": {
                      "type": "number",
                      "description": "Confidence score for event detection (0.0 to 1.0)"
                    },
                    "metrics": {
                      "type": "object",
                      "description": "Detailed metrics for the detected event"
                    },
                    "trip_analytics": {
                      "type": "object",
                      "description": "Updated real-time trip analytics\n  \n  \n    \n      Current total distance for the trip"
                    },
                    "duration_minutes": {
                      "type": "number",
                      "description": "Current trip duration in minutes"
                    },
                    "avg_speed_kmh": {
                      "type": "number",
                      "description": "Current average speed for the trip"
                    },
                    "current_safety_score": {
                      "type": "integer",
                      "description": "Real-time safety score (0-100)"
                    },
                    "locations_count": {
                      "type": "integer",
                      "description": "Total number of location points received"
                    },
                    "quality_assessment": {
                      "type": "object",
                      "description": "Assessment of the location data quality\n  \n  \n    \n      GPS accuracy rating: \"excellent\", \"good\", \"fair\", \"poor\""
                    },
                    "signal_quality": {
                      "type": "string",
                      "description": "Overall signal quality assessment"
                    },
                    "deviation_from_route": {
                      "type": "number",
                      "description": "Distance in meters from expected route (if available)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "trip_id": {
                    "type": "string",
                    "description": "Unique identifier for the active trip to upload the location to"
                  },
                  "latitude": {
                    "type": "number",
                    "description": "Latitude coordinate in decimal degrees (-90 to 90)"
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Longitude coordinate in decimal degrees (-180 to 180)"
                  },
                  "timestamp": {
                    "type": "string",
                    "description": "ISO 8601 timestamp when the location was recorded"
                  },
                  "speed_kmh": {
                    "type": "number",
                    "description": "Vehicle speed in kilometers per hour at this location"
                  },
                  "heading": {
                    "type": "number",
                    "description": "Direction of travel in degrees (0-360, where 0 is North)"
                  },
                  "accuracy_meters": {
                    "type": "number",
                    "description": "GPS accuracy in meters (lower values indicate better accuracy)"
                  },
                  "altitude_meters": {
                    "type": "number",
                    "description": "Altitude above sea level in meters"
                  },
                  "battery_level": {
                    "type": "number",
                    "description": "Device battery level percentage (0-100)"
                  },
                  "network_type": {
                    "type": "string",
                    "description": "Network connection type: \"wifi\", \"cellular\", \"offline\""
                  },
                  "device_info": {
                    "type": "object",
                    "description": "Device information for this location point\n  \n  \n    \n      Unique device identifier"
                  },
                  "signal_strength": {
                    "type": "integer",
                    "description": "Network signal strength (-100 to 0 dBm for cellular)"
                  },
                  "satellites_count": {
                    "type": "integer",
                    "description": "Number of GPS satellites used for positioning"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "locations"
        ]
      }
    },
    "/api/tiles/buildings/metadata": {
      "get": {
        "summary": "Get Buildings Metadata",
        "description": "Retrieve detailed metadata and header information for the buildings PMTiles archive",
        "operationId": "GetBuildingsMetadata",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "file": {
                      "type": "string",
                      "description": "PMTiles filename\n  \n  Example: `usa-buildings.pmtiles`"
                    },
                    "url": {
                      "type": "string",
                      "description": "Direct URL to PMTiles archive\n  \n  Example: `https://maptiles.bookovia.com/usa-buildings.pmtiles`"
                    },
                    "header": {
                      "type": "object",
                      "description": "PMTiles header information\n  \n  \n    \n      PMTiles specification version\n      \n      Value: `3`"
                    },
                    "minZoom": {
                      "type": "integer",
                      "description": "Minimum available zoom level\n      \n      Value: `0`"
                    },
                    "maxZoom": {
                      "type": "integer",
                      "description": "Maximum available zoom level\n      \n      Value: `15`"
                    },
                    "minLon": {
                      "type": "number",
                      "description": "Minimum longitude (west) of bounding box\n      \n      Example: `-179.1473`"
                    },
                    "minLat": {
                      "type": "number",
                      "description": "Minimum latitude (south) of bounding box\n      \n      Example: `18.9110`"
                    },
                    "maxLon": {
                      "type": "number",
                      "description": "Maximum longitude (east) of bounding box\n      \n      Example: `-66.9498`"
                    },
                    "maxLat": {
                      "type": "number",
                      "description": "Maximum latitude (north) of bounding box\n      \n      Example: `71.3577`"
                    },
                    "centerZoom": {
                      "type": "integer",
                      "description": "Recommended center zoom level\n      \n      Example: `4`"
                    },
                    "centerLon": {
                      "type": "number",
                      "description": "Recommended center longitude\n      \n      Example: `-98.5795`"
                    },
                    "centerLat": {
                      "type": "number",
                      "description": "Recommended center latitude\n      \n      Example: `39.8283`"
                    },
                    "tileType": {
                      "type": "string",
                      "description": "Tile data type\n      \n      Value: `mvt` (Mapbox Vector Tiles)"
                    },
                    "compression": {
                      "type": "string",
                      "description": "Tile compression method\n      \n      Value: `gzip`"
                    },
                    "tileDataSize": {
                      "type": "integer",
                      "description": "Total size of tile data section in bytes\n      \n      Example: `9935166203` (~9.25 GB)"
                    },
                    "metadataSize": {
                      "type": "integer",
                      "description": "Size of metadata section in bytes"
                    },
                    "metadata": {
                      "type": "string",
                      "description": "JSON-encoded metadata from PMTiles archive\n  \n  Contains layer schemas, attribution, and data source information"
                    },
                    "error": {
                      "type": "string",
                      "description": "Error message if the request failed"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "maps"
        ]
      }
    },
    "/tiles/buildings/{z}/{x}/{y}.mvt": {
      "get": {
        "summary": "Get Buildings Tile",
        "description": "Retrieve vector tile data for building footprints across the United States",
        "operationId": "GetBuildingsTile",
        "parameters": [
          {
            "name": "z",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Zoom level (0-15)\n  \n  Higher zoom levels show more detail. Tiles are optimized for zoom 13+ where individual buildings are visible."
          },
          {
            "name": "x",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Tile X coordinate at the specified zoom level\n  \n  Range: 0 to 2^z - 1"
          },
          {
            "name": "y",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Tile Y coordinate at the specified zoom level\n  \n  Range: 0 to 2^z - 1\n  \n  Note: Can include `.mvt` extension (e.g., `395.mvt`)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "buildings": {
                      "type": "layer",
                      "description": "Vector layer containing building geometries\n  \n  \n    \n      Unique building identifier (GERS ID from Overture Maps)"
                    },
                    "height": {
                      "type": "number",
                      "description": "Building height in meters\n      \n      Note: May be null for buildings without height data"
                    },
                    "building_type": {
                      "type": "string",
                      "description": "Building classification\n      \n      Values: `residential`, `commercial`, `industrial`, `institutional`, `mixed_use`, `other`"
                    },
                    "address": {
                      "type": "string",
                      "description": "Street address if available\n      \n      Format: `123 Main St`"
                    },
                    "num_floors": {
                      "type": "integer",
                      "description": "Number of floors\n      \n      Estimated from height if not explicitly provided"
                    },
                    "geometry": {
                      "type": "polygon",
                      "description": "Building footprint as polygon coordinates"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "maps"
        ]
      }
    },
    "/api/tiles/roads/metadata": {
      "get": {
        "summary": "Get Roads Metadata",
        "description": "Retrieve detailed metadata and header information for the roads PMTiles archive",
        "operationId": "GetRoadsMetadata",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "file": {
                      "type": "string",
                      "description": "PMTiles filename\n  \n  Value: `usa-roads.pmtiles`"
                    },
                    "url": {
                      "type": "string",
                      "description": "Direct URL to PMTiles archive\n  \n  Value: `https://maptiles.bookovia.com/usa-roads.pmtiles`"
                    },
                    "header": {
                      "type": "object",
                      "description": "PMTiles header with zoom levels, bounds, and size information"
                    },
                    "metadata": {
                      "type": "string",
                      "description": "JSON-encoded metadata including road layer schema"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "maps"
        ]
      }
    },
    "/tiles/roads/{z}/{x}/{y}.mvt": {
      "get": {
        "summary": "Get Roads Tile",
        "description": "Retrieve vector tile data for road networks across the United States",
        "operationId": "GetRoadsTile",
        "parameters": [
          {
            "name": "z",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Zoom level (0-15)\n  \n  Lower zooms show major highways only. Higher zooms include residential streets and paths."
          },
          {
            "name": "x",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Tile X coordinate at the specified zoom level\n  \n  Range: 0 to 2^z - 1"
          },
          {
            "name": "y",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Tile Y coordinate at the specified zoom level\n  \n  Range: 0 to 2^z - 1\n  \n  Note: Can include `.mvt` extension (e.g., `395.mvt`)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "roads": {
                      "type": "layer",
                      "description": "Vector layer containing road geometries\n  \n  \n    \n      Unique road segment identifier (GERS ID from Overture Maps)"
                    },
                    "class": {
                      "type": "string",
                      "description": "Road classification\n      \n      Values: `motorway`, `trunk`, `primary`, `secondary`, `tertiary`, `residential`, `service`, `path`, `cycleway`, `footway`"
                    },
                    "name": {
                      "type": "string",
                      "description": "Street name\n      \n      Example: `Broadway`, `Interstate 80`, `Main Street`"
                    },
                    "ref": {
                      "type": "string",
                      "description": "Road reference/number\n      \n      Example: `I-80`, `US-101`, `CA-1`"
                    },
                    "lanes": {
                      "type": "integer",
                      "description": "Number of lanes (total, both directions)\n      \n      Example: 4 (2 lanes each direction)"
                    },
                    "surface": {
                      "type": "string",
                      "description": "Road surface type\n      \n      Values: `paved`, `unpaved`, `gravel`, `dirt`, `concrete`, `asphalt`"
                    },
                    "speed_limit": {
                      "type": "integer",
                      "description": "Speed limit in km/h\n      \n      Note: May be null if not explicitly tagged"
                    },
                    "oneway": {
                      "type": "boolean",
                      "description": "Whether road is one-way\n      \n      Default: false (two-way)"
                    },
                    "bridge": {
                      "type": "boolean",
                      "description": "Whether segment is a bridge"
                    },
                    "tunnel": {
                      "type": "boolean",
                      "description": "Whether segment is a tunnel"
                    },
                    "toll": {
                      "type": "boolean",
                      "description": "Whether segment has tolls"
                    },
                    "access": {
                      "type": "string",
                      "description": "Access restrictions\n      \n      Values: `public`, `private`, `permissive`, `customers`, `delivery`"
                    },
                    "geometry": {
                      "type": "linestring",
                      "description": "Road centerline as line coordinates"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "maps"
        ]
      }
    },
    "/api/tiles/stats": {
      "get": {
        "summary": "Get Tile Statistics",
        "description": "Retrieve metadata, coverage, and statistics for available map tile sources",
        "operationId": "GetTileStatistics",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "sources": {
                      "type": "array",
                      "description": "Array of available tile sources with their metadata\n  \n  \n    \n      Unique identifier for the tile source\n      \n      Values: `buildings`, `roads`"
                    },
                    "name": {
                      "type": "string",
                      "description": "Human-readable name\n      \n      Example: `USA Buildings`"
                    },
                    "file": {
                      "type": "string",
                      "description": "PMTiles filename\n      \n      Example: `usa-buildings.pmtiles`"
                    },
                    "url": {
                      "type": "string",
                      "description": "Direct URL to PMTiles archive\n      \n      Example: `https://maptiles.bookovia.com/usa-buildings.pmtiles`"
                    },
                    "size": {
                      "type": "string",
                      "description": "Archive file size\n      \n      Example: `9.25 GB`"
                    },
                    "features": {
                      "type": "string",
                      "description": "Estimated feature count\n      \n      Example: `~150M building footprints`"
                    },
                    "coverage": {
                      "type": "string",
                      "description": "Geographic coverage area\n      \n      Example: `United States`"
                    },
                    "attributes": {
                      "type": "array<string>",
                      "description": "Available feature properties\n      \n      Example: `[\"height\", \"building_type\", \"address\"]`"
                    },
                    "zoomLevels": {
                      "type": "string",
                      "description": "Available zoom range\n      \n      Example: `0-15`"
                    },
                    "endpoint": {
                      "type": "string",
                      "description": "Tile endpoint URL pattern\n      \n      Example: `/tiles/buildings/{z}/{x}/{y}.mvt`"
                    },
                    "format": {
                      "type": "string",
                      "description": "Tile archive format\n  \n  Value: `PMTiles v3 (Protomaps)`"
                    },
                    "protocol": {
                      "type": "string",
                      "description": "Vector tile protocol\n  \n  Value: `Mapbox Vector Tiles (MVT)`"
                    },
                    "error": {
                      "type": "string",
                      "description": "Error message if the request failed"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "maps"
        ]
      }
    },
    "/routing/centroid": {
      "post": {
        "summary": "Centroid",
        "description": "Documentation coming soon",
        "operationId": "Centroid",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/expansion": {
      "post": {
        "summary": "Expansion",
        "description": "Documentation coming soon",
        "operationId": "Expansion",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/height": {
      "post": {
        "summary": "Height",
        "description": "Documentation coming soon",
        "operationId": "Height",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/isochrone": {
      "post": {
        "summary": "Isochrone",
        "description": "Generate polygons showing areas reachable within specific time or distance limits from a location",
        "operationId": "Isochrone",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "locations": {
                    "type": "array",
                    "description": "Starting location(s) for isochrone calculation (typically 1 location)\n  \n  \n    \n      Latitude in decimal degrees"
                  },
                  "lon": {
                    "type": "number",
                    "description": "Longitude in decimal degrees"
                  },
                  "costing": {
                    "type": "string",
                    "description": "Transportation mode\n  \n  Options: `auto`, `bicycle`, `pedestrian`, `truck`"
                  },
                  "contours": {
                    "type": "array",
                    "description": "Array of time or distance contours to calculate\n  \n  \n    \n      Time in minutes (use either `time` or `distance`, not both)"
                  },
                  "distance": {
                    "type": "number",
                    "description": "Distance in kilometers (use either `time` or `distance`)"
                  },
                  "color": {
                    "type": "string",
                    "description": "Hex color for visualization (e.g., \"ff0000\")"
                  },
                  "polygons": {
                    "type": "boolean",
                    "description": "Return polygons instead of lines\n  \n  Default: `true`"
                  },
                  "denoise": {
                    "type": "number",
                    "description": "Remove small disconnected polygons (0.0-1.0, where 1.0 removes most)\n  \n  Default: 0.0"
                  },
                  "generalize": {
                    "type": "number",
                    "description": "Simplify polygon geometry (meters tolerance)\n  \n  Default: 50"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/locate": {
      "post": {
        "summary": "Locate",
        "description": "Documentation coming soon",
        "operationId": "Locate",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/optimized_route": {
      "post": {
        "summary": "Optimized Route",
        "description": "Calculate the optimal order for visiting multiple stops to minimize travel time or distance",
        "operationId": "OptimizedRoute",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Optimized route with reordered locations\n  \n  \n    \n      Complete trip with optimized stop order\n      \n      \n        \n          Locations in optimized visit order (first and last remain fixed)"
                    },
                    "legs": {
                      "type": "array",
                      "description": "Route segments between optimized stops"
                    },
                    "summary": {
                      "type": "object",
                      "description": "Overall trip statistics\n          \n          \n            \n              Total optimized distance"
                    },
                    "time": {
                      "type": "number",
                      "description": "Total optimized time in seconds"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "locations": {
                    "type": "array",
                    "description": "Array of locations to visit (minimum 4, maximum 50). The first location is the start point, the last is the end point, and all intermediate locations will be reordered for optimization.\n  \n  \n    \n   "
                  },
                  "lon": {
                    "type": "number",
                    "description": "Longitude in decimal degrees (-180 to 180)"
                  },
                  "costing": {
                    "type": "string",
                    "description": "Transportation mode for routing calculation\n  \n  Options: `auto`, `truck`, `bicycle`, `pedestrian`, `motorcycle`, `motor_scooter`, `bus`, `taxi`\n  \n  Default: `auto`"
                  },
                  "costing_options": {
                    "type": "object",
                    "description": "Mode-specific routing preferences (same options as `/route` endpoint)"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/route": {
      "post": {
        "summary": "Get Route",
        "description": "Calculate turn-by-turn driving, walking, or cycling directions between multiple locations",
        "operationId": "GetRoute",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Route calculation result\n  \n  \n    \n      Complete trip information with all route segments\n      \n      \n        \n          Waypoint locations with matched road coordinates"
                    },
                    "legs": {
                      "type": "array",
                      "description": "Route segments between waypoints\n          \n          \n            \n              Turn-by-turn navigation instructions\n              \n              \n                \n                  Maneuver type co"
                    },
                    "instruction": {
                      "type": "string",
                      "description": "Human-readable instruction"
                    },
                    "street_names": {
                      "type": "array",
                      "description": "Road names for this maneuver"
                    },
                    "length": {
                      "type": "number",
                      "description": "Segment length in kilometers or miles"
                    },
                    "time": {
                      "type": "number",
                      "description": "Total time in seconds"
                    },
                    "begin_shape_index": {
                      "type": "integer",
                      "description": "Start index in shape array"
                    },
                    "end_shape_index": {
                      "type": "integer",
                      "description": "End index in shape array"
                    },
                    "verbal_pre_transition_instruction": {
                      "type": "string",
                      "description": "Voice instruction before maneuver"
                    },
                    "verbal_post_transition_instruction": {
                      "type": "string",
                      "description": "Voice instruction after maneuver"
                    },
                    "summary": {
                      "type": "object",
                      "description": "Overall trip statistics\n          \n          \n            \n              Total distance in kilometers or miles"
                    },
                    "shape": {
                      "type": "string",
                      "description": "Encoded polyline of route geometry"
                    },
                    "min_lat": {
                      "type": "number",
                      "description": "Bounding box minimum latitude"
                    },
                    "max_lat": {
                      "type": "number",
                      "description": "Bounding box maximum latitude"
                    },
                    "min_lon": {
                      "type": "number",
                      "description": "Bounding box minimum longitude"
                    },
                    "max_lon": {
                      "type": "number",
                      "description": "Bounding box maximum longitude"
                    },
                    "error": {
                      "type": "string",
                      "description": "Error message if the request failed"
                    },
                    "details": {
                      "type": "string",
                      "description": "Detailed error information from routing engine"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "locations": {
                    "type": "array",
                    "description": "Array of waypoint locations (minimum 2, maximum 50). Routes will be calculated in the order provided.\n  \n  \n    \n      Latitude in decimal degrees (-90 to 90)"
                  },
                  "lon": {
                    "type": "number",
                    "description": "Longitude in decimal degrees (-180 to 180)"
                  },
                  "type": {
                    "type": "string",
                    "description": "Location type: `break` (stop at location), `through` (pass through), `via` (intermediate waypoint)\n      \n      Default: `break`"
                  },
                  "heading": {
                    "type": "integer",
                    "description": "Preferred initial heading in degrees (0-359). Used to influence route direction from this location."
                  },
                  "heading_tolerance": {
                    "type": "integer",
                    "description": "Tolerance for heading match in degrees (0-180)\n      \n      Default: 60"
                  },
                  "street_side_tolerance": {
                    "type": "number",
                    "description": "Maximum distance (meters) to snap to correct side of street\n      \n      Default: 5"
                  },
                  "costing": {
                    "type": "string",
                    "description": "Transportation mode for routing calculation\n  \n  Options: `auto`, `auto_shorter`, `truck`, `bicycle`, `pedestrian`, `motorcycle`, `motor_scooter`, `bus`, `taxi`, `bikeshare`\n  \n  Default: `auto`"
                  },
                  "costing_options": {
                    "type": "object",
                    "description": "Mode-specific routing preferences and vehicle constraints\n  \n  \n    \n      Cost penalty for turns and maneuvers (seconds)\n      \n      Default: 5"
                  },
                  "use_highways": {
                    "type": "number",
                    "description": "Preference for highways (0.0 = avoid, 1.0 = prefer)\n      \n      Default: 1.0"
                  },
                  "use_tolls": {
                    "type": "number",
                    "description": "Preference for toll roads (0.0 = avoid, 1.0 = prefer)\n      \n      Default: 0.5"
                  },
                  "use_ferry": {
                    "type": "number",
                    "description": "Preference for ferries (0.0 = avoid, 1.0 = prefer)\n      \n      Default: 0.5"
                  },
                  "top_speed": {
                    "type": "number",
                    "description": "Maximum speed in km/h\n      \n      Default: 140 (auto), 120 (truck/motorcycle)"
                  },
                  "exclude_unpaved": {
                    "type": "boolean",
                    "description": "Avoid unpaved roads\n      \n      Default: false"
                  },
                  "exclude_cash_only_tolls": {
                    "type": "boolean",
                    "description": "Avoid cash-only toll roads\n      \n      Default: false"
                  },
                  "shortest": {
                    "type": "boolean",
                    "description": "Prefer shortest distance over fastest time\n      \n      Default: false"
                  },
                  "height": {
                    "type": "number",
                    "description": "Vehicle height in meters"
                  },
                  "width": {
                    "type": "number",
                    "description": "Vehicle width in meters"
                  },
                  "length": {
                    "type": "number",
                    "description": "Vehicle length in meters"
                  },
                  "weight": {
                    "type": "number",
                    "description": "Vehicle weight in metric tons"
                  },
                  "axle_load": {
                    "type": "number",
                    "description": "Weight per axle in metric tons"
                  },
                  "axle_count": {
                    "type": "integer",
                    "description": "Number of axles"
                  },
                  "hazmat": {
                    "type": "boolean",
                    "description": "Vehicle carries hazardous materials\n      \n      Default: false"
                  },
                  "use_truck_route": {
                    "type": "boolean",
                    "description": "Prefer designated truck routes\n      \n      Default: true"
                  },
                  "bicycle_type": {
                    "type": "string",
                    "description": "Bicycle type: `Hybrid`, `Road`, `Mountain`, `Cross`\n      \n      Default: `Hybrid`"
                  },
                  "cycling_speed": {
                    "type": "number",
                    "description": "Average cycling speed in km/h\n      \n      Default: 20"
                  },
                  "use_roads": {
                    "type": "number",
                    "description": "Willingness to ride on roads (0.0-1.0)\n      \n      Default: 0.5"
                  },
                  "use_hills": {
                    "type": "number",
                    "description": "Willingness to climb hills (0.0-1.0)\n      \n      Default: 0.5"
                  },
                  "avoid_bad_surfaces": {
                    "type": "number",
                    "description": "Avoid unpaved surfaces (0.0-1.0)\n      \n      Default: 0.8"
                  },
                  "use_bike_lanes": {
                    "type": "number",
                    "description": "Preference for bike lanes (0.0-1.0)\n      \n      Default: 1.0"
                  },
                  "walking_speed": {
                    "type": "number",
                    "description": "Average walking speed in km/h\n      \n      Default: 5.1"
                  },
                  "walkway_factor": {
                    "type": "number",
                    "description": "Preference for walkways vs roads (0.0-1.0)\n      \n      Default: 1.0"
                  },
                  "sidewalk_factor": {
                    "type": "number",
                    "description": "Preference for sidewalks (0.0-1.0)\n      \n      Default: 1.0"
                  },
                  "step_penalty": {
                    "type": "number",
                    "description": "Time penalty for stairs/steps (seconds)\n      \n      Default: 30"
                  },
                  "max_hiking_difficulty": {
                    "type": "integer",
                    "description": "Maximum trail difficulty (0=none to 6=difficult)\n      \n      Default: 1"
                  },
                  "directions_options": {
                    "type": "object",
                    "description": "Output format and display preferences\n  \n  \n    \n      Distance units: `kilometers` or `miles`\n      \n      Default: `kilometers`"
                  },
                  "language": {
                    "type": "string",
                    "description": "Instruction language code (e.g., `en`, `es`, `fr`, `de`, `it`)\n      \n      Default: `en`"
                  },
                  "directions_type": {
                    "type": "string",
                    "description": "Level of detail: `none`, `maneuvers`, `instructions`\n      \n      Default: `instructions`"
                  },
                  "format": {
                    "type": "string",
                    "description": "Response format: `json`, `gpx`, `osrm`\n      \n      Default: `json`"
                  },
                  "alternates": {
                    "type": "integer",
                    "description": "Number of alternative routes to return (0-2)\n  \n  Default: 0"
                  },
                  "date_time": {
                    "type": "object",
                    "description": "Time-based routing for traffic-aware calculations\n  \n  \n    \n      Time type: `0` (depart at), `1` (arrive by), `2` (current time)"
                  },
                  "value": {
                    "type": "string",
                    "description": "ISO 8601 timestamp (required if type is 0 or 1)\n      \n      Example: `2026-04-21T08:00:00`"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/sources_to_targets": {
      "post": {
        "summary": "Distance Matrix",
        "description": "Calculate distances and travel times between multiple source and target locations in a single request",
        "operationId": "DistanceMatrix",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates whether the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Distance matrix results\n  \n  \n    \n      2D array where `[i][j]` contains distance/time from source `i` to target `j`\n      \n      \n        \n          Distance in kilometers"
                    },
                    "time": {
                      "type": "number",
                      "description": "Travel time in seconds"
                    },
                    "units": {
                      "type": "string",
                      "description": "Distance units used (kilometers or miles)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "sources": {
                    "type": "array",
                    "description": "Array of source (origin) locations (maximum 50)\n  \n  \n    \n      Latitude in decimal degrees"
                  },
                  "lon": {
                    "type": "number",
                    "description": "Longitude in decimal degrees"
                  },
                  "targets": {
                    "type": "array",
                    "description": "Array of target (destination) locations (maximum 50)\n  \n  \n    \n      Latitude in decimal degrees"
                  },
                  "costing": {
                    "type": "string",
                    "description": "Transportation mode\n  \n  Options: `auto`, `truck`, `bicycle`, `pedestrian`"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/status": {
      "get": {
        "summary": "API Status",
        "description": "Check routing API health and get information about available endpoints and data coverage",
        "operationId": "APIStatus",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/trace-attributes": {
      "post": {
        "summary": "Trace Attributes",
        "description": "Documentation coming soon",
        "operationId": "TraceAttributes",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/trace_route": {
      "post": {
        "summary": "Map Matching",
        "description": "Snap GPS traces to the road network for accurate route reconstruction and mileage calculation",
        "operationId": "MapMatching",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "shape": {
                    "type": "array",
                    "description": "Array of GPS points to match (minimum 2 points)\n  \n  \n    \n      Latitude"
                  },
                  "lon": {
                    "type": "number",
                    "description": "Longitude"
                  },
                  "time": {
                    "type": "number",
                    "description": "Unix timestamp (seconds)"
                  },
                  "costing": {
                    "type": "string",
                    "description": "Transportation mode: `auto`, `truck`, `bicycle`, `pedestrian`"
                  },
                  "shape_match": {
                    "type": "string",
                    "description": "Matching algorithm: `map_snap` (snap to nearest roads), `edge_walk` (walk road network), `walk_or_snap` (hybrid)\n  \n  Default: `map_snap`"
                  },
                  "gps_accuracy": {
                    "type": "number",
                    "description": "GPS accuracy in meters\n  \n  Default: 5"
                  },
                  "search_radius": {
                    "type": "number",
                    "description": "Maximum search distance for road matching (meters)\n  \n  Default: 50"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/routing/transit-available": {
      "post": {
        "summary": "Transit Available",
        "description": "Documentation coming soon",
        "operationId": "TransitAvailable",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "routing"
        ]
      }
    },
    "/trips/{sessionId}/export": {
      "get": {
        "summary": "Export Trip Data",
        "description": "Export comprehensive trip data in various formats for analysis and reporting",
        "operationId": "ExportTripData",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the trip session to export. This is the trip ID returned from the Start Trip endpoint."
          },
          {
            "name": "format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Export format. Options: `json`, `csv`, `gpx`, `kml`"
          },
          {
            "name": "include",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Comma-separated data types to include. Options: `route`, `analytics`, `events`, `telemetry`, `safety`, `all`\n  Default: `route,analytics,events`"
          },
          {
            "name": "time_zone",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Timezone for timestamps. Example: `Europe/London`, `America/New_York`"
          },
          {
            "name": "compression",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to compress the export file (gzip)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "export_id": {
                      "type": "string",
                      "description": "Unique identifier for this export request"
                    },
                    "trip_id": {
                      "type": "string",
                      "description": "The trip ID that was exported"
                    },
                    "format": {
                      "type": "string",
                      "description": "Export format used"
                    },
                    "file_size": {
                      "type": "number",
                      "description": "Size of exported file in bytes"
                    },
                    "download_url": {
                      "type": "string",
                      "description": "Pre-signed URL to download the exported file (expires in 24 hours)"
                    },
                    "generated_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when export was generated"
                    },
                    "expires_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when download URL expires"
                    },
                    "metadata": {
                      "type": "object",
                      "description": "Export metadata and statistics\n  \n    \n      Number of location records in export"
                    },
                    "events_count": {
                      "type": "number",
                      "description": "Number of events in export"
                    },
                    "duration_seconds": {
                      "type": "number",
                      "description": "Total trip duration in seconds"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Total distance in kilometers"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/users/{userId}/trips/active": {
      "get": {
        "summary": "Get User Active Trips",
        "description": "Retrieve all currently active trips (recording or paused) for a specific user",
        "operationId": "GetUserActiveTrips",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the user whose active trips you want to retrieve"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates if the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Response data object\n  \n    \n      Array of active trip objects\n      \n        \n          Unique identifier for the trip"
                    },
                    "org_id": {
                      "type": "string",
                      "description": "Organization ID associated with this trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle ID associated with this trip"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User ID associated with this trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status: \"recording\" or \"paused\""
                    },
                    "purpose": {
                      "type": "string",
                      "description": "Trip purpose: \"personal\", \"business\", \"commute\", \"errand\""
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip started"
                    },
                    "duration_seconds": {
                      "type": "number",
                      "description": "Trip duration in seconds (null if not yet calculated)"
                    },
                    "distance_meters": {
                      "type": "number",
                      "description": "Distance traveled in meters (null if not yet calculated)"
                    },
                    "created_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip was created"
                    },
                    "count": {
                      "type": "number",
                      "description": "Total number of active trips returned"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/wss://api.bookovia.com/v1/trips/{sessionId}/mileage/live": {
      "wss": {
        "summary": "Real-Time Trip Mileage (WebSocket)",
        "description": "Stream real-time trip mileage updates via WebSocket for smooth, live tracking with sub-100ms latency",
        "operationId": "RealTimeTripMileageWebSocket",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The trip ID to stream real-time updates for"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {}
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/organizations/{orgId}/trips/active": {
      "get": {
        "summary": "Get Organization Active Trips",
        "description": "Retrieve all currently active trips (recording or paused) across an entire organization",
        "operationId": "GetOrganizationActiveTrips",
        "parameters": [
          {
            "name": "orgId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the organization whose active trips you want to retrieve"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates if the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Response data object\n  \n    \n      Array of active trip objects across all organization vehicles and users\n      \n        \n          Unique identifier for the trip"
                    },
                    "org_id": {
                      "type": "string",
                      "description": "Organization ID associated with this trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle ID associated with this trip"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User ID associated with this trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status: \"recording\" or \"paused\""
                    },
                    "purpose": {
                      "type": "string",
                      "description": "Trip purpose: \"personal\", \"business\", \"commute\", \"errand\""
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip started"
                    },
                    "duration_seconds": {
                      "type": "number",
                      "description": "Trip duration in seconds (null if not yet calculated)"
                    },
                    "distance_meters": {
                      "type": "number",
                      "description": "Distance traveled in meters (null if not yet calculated)"
                    },
                    "created_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip was created"
                    },
                    "count": {
                      "type": "number",
                      "description": "Total number of active trips returned"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/organizations/{orgId}/trips/history": {
      "get": {
        "summary": "Get Organization Trip History",
        "description": "Retrieve completed trip history for an entire organization with optional status filtering",
        "operationId": "GetOrganizationTripHistory",
        "parameters": [
          {
            "name": "orgId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the organization whose trip history you want to retrieve"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter trips by status. If not provided, defaults to \"completed\". Valid values: \"completed\", \"cancelled\", \"recording\", \"paused\""
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates if the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Response data object\n  \n    \n      Array of trip objects across all organization vehicles and users\n      \n        \n          Unique identifier for the trip"
                    },
                    "org_id": {
                      "type": "string",
                      "description": "Organization ID associated with this trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle ID associated with this trip"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User ID associated with this trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status: \"completed\", \"cancelled\", \"recording\", \"paused\""
                    },
                    "purpose": {
                      "type": "string",
                      "description": "Trip purpose: \"personal\", \"business\", \"commute\", \"errand\""
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip started"
                    },
                    "end_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip ended (null for incomplete trips)"
                    },
                    "duration_seconds": {
                      "type": "number",
                      "description": "Trip duration in seconds (null if not calculated)"
                    },
                    "distance_meters": {
                      "type": "number",
                      "description": "Distance traveled in meters (null if not calculated)"
                    },
                    "created_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip was created"
                    },
                    "count": {
                      "type": "number",
                      "description": "Total number of trips returned"
                    },
                    "filter": {
                      "type": "string",
                      "description": "The status filter applied (if any)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{sessionId}/with-analytics": {
      "get": {
        "summary": "Get Trip with Analytics",
        "description": "Get comprehensive trip details from Postgres combined with real-time analytics from DuckDB",
        "operationId": "GetTripwithAnalytics",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The trip ID to query"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Combined trip and analytics data\n  \n  \n    \n      Trip metadata from Postgres\n      \n      \n        \n          Trip identifier"
                    },
                    "org_id": {
                      "type": "string",
                      "description": "Organization identifier"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle identifier"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "Driver identifier"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status (recording, paused, completed, cancelled)"
                    },
                    "purpose": {
                      "type": "string",
                      "description": "Trip purpose (personal, business, etc.)"
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip started"
                    },
                    "end_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip ended (null if active)"
                    },
                    "duration_seconds": {
                      "type": "integer",
                      "description": "Trip duration in seconds"
                    },
                    "distance_meters": {
                      "type": "number",
                      "description": "Distance from Postgres (may be outdated, use analytics instead)"
                    },
                    "analytics": {
                      "type": "object",
                      "description": "Real-time analytics from DuckDB\n      \n      \n        \n          Number of GPS points recorded"
                    },
                    "calculated_miles": {
                      "type": "number",
                      "description": "Accurate distance from GPS data (miles)"
                    },
                    "calculated_km": {
                      "type": "number",
                      "description": "Accurate distance from GPS data (kilometers)"
                    },
                    "avg_speed_kmh": {
                      "type": "number",
                      "description": "Average speed in km/h"
                    },
                    "max_speed_kmh": {
                      "type": "number",
                      "description": "Maximum speed reached in km/h"
                    },
                    "data_source": {
                      "type": "string",
                      "description": "Source of analytics data (e.g., \"duckdb_parquet\")"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/users/{userId}/trips/history": {
      "get": {
        "summary": "Get User Trip History",
        "description": "Retrieve completed trip history for a specific user with optional status filtering",
        "operationId": "GetUserTripHistory",
        "parameters": [
          {
            "name": "userId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the user whose trip history you want to retrieve"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter trips by status. If not provided, defaults to \"completed\". Valid values: \"completed\", \"cancelled\", \"recording\", \"paused\""
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates if the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Response data object\n  \n    \n      Array of trip objects\n      \n        \n          Unique identifier for the trip"
                    },
                    "org_id": {
                      "type": "string",
                      "description": "Organization ID associated with this trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle ID associated with this trip"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User ID associated with this trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status: \"completed\", \"cancelled\", \"recording\", \"paused\""
                    },
                    "purpose": {
                      "type": "string",
                      "description": "Trip purpose: \"personal\", \"business\", \"commute\", \"errand\""
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip started"
                    },
                    "end_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip ended (null for incomplete trips)"
                    },
                    "duration_seconds": {
                      "type": "number",
                      "description": "Trip duration in seconds (null if not calculated)"
                    },
                    "distance_meters": {
                      "type": "number",
                      "description": "Distance traveled in meters (null if not calculated)"
                    },
                    "created_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip was created"
                    },
                    "count": {
                      "type": "number",
                      "description": "Total number of trips returned"
                    },
                    "filter": {
                      "type": "string",
                      "description": "The status filter applied (if any)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{trip_id}/summary": {
      "get": {
        "summary": "Get Trip Summary",
        "description": "Get comprehensive analytics and performance summary for a completed trip",
        "operationId": "GetTripSummary",
        "parameters": [
          {
            "name": "trip_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique identifier for the trip to get summary for"
          },
          {
            "name": "include_benchmarks",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include performance benchmarks compared to organization averages"
          },
          {
            "name": "include_route_analysis",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include detailed route analysis and optimization suggestions"
          },
          {
            "name": "export_format",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Response format. Options: \"json\", \"pdf_url\" (generates downloadable PDF report)"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the trip"
                    },
                    "summary_generated_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when this summary was generated"
                    },
                    "trip_overview": {
                      "type": "object",
                      "description": "Basic trip information and metrics\n  \n  \n    \n      Trip start timestamp"
                    },
                    "end_time": {
                      "type": "string",
                      "description": "Trip end timestamp"
                    },
                    "duration_minutes": {
                      "type": "number",
                      "description": "Total trip duration"
                    },
                    "distance_km": {
                      "type": "number",
                      "description": "Total distance traveled"
                    },
                    "status": {
                      "type": "string",
                      "description": "Final trip status"
                    },
                    "performance_metrics": {
                      "type": "object",
                      "description": "Detailed performance and efficiency metrics\n  \n  \n    \n      Overall safety score (0-100)"
                    },
                    "eco_score": {
                      "type": "integer",
                      "description": "Eco-driving score (0-100)"
                    },
                    "efficiency_score": {
                      "type": "integer",
                      "description": "Route efficiency score (0-100)"
                    },
                    "avg_speed_kmh": {
                      "type": "number",
                      "description": "Average speed throughout trip"
                    },
                    "max_speed_kmh": {
                      "type": "number",
                      "description": "Maximum speed reached"
                    },
                    "idle_time_minutes": {
                      "type": "number",
                      "description": "Total idle time"
                    },
                    "driving_behavior": {
                      "type": "object",
                      "description": "Detailed analysis of driving behavior and events\n  \n  \n    \n      Count and severity of harsh driving events"
                    },
                    "speeding_analysis": {
                      "type": "object",
                      "description": "Speeding incidents and severity"
                    },
                    "smoothness_score": {
                      "type": "integer",
                      "description": "Driving smoothness score (0-100)"
                    },
                    "distraction_indicators": {
                      "type": "array",
                      "description": "Potential distraction events detected"
                    },
                    "fuel_analysis": {
                      "type": "object",
                      "description": "Fuel consumption and efficiency analysis\n  \n  \n    \n      Total fuel consumed"
                    },
                    "fuel_efficiency_kmpl": {
                      "type": "number",
                      "description": "Fuel efficiency in km per liter"
                    },
                    "co2_emissions_kg": {
                      "type": "number",
                      "description": "Estimated CO2 emissions"
                    },
                    "efficiency_rating": {
                      "type": "string",
                      "description": "Efficiency rating: \"excellent\", \"good\", \"average\", \"poor\""
                    },
                    "route_analysis": {
                      "type": "object",
                      "description": "Route optimization and efficiency analysis\n  \n  \n    \n      Comparison between planned and actual route"
                    },
                    "traffic_impact": {
                      "type": "object",
                      "description": "Analysis of traffic conditions impact"
                    },
                    "optimization_suggestions": {
                      "type": "array",
                      "description": "Route optimization recommendations"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{trip_id}": {
      "get": {
        "summary": "Get Trip",
        "description": "Retrieve detailed information about a specific trip including real-time analytics and location data",
        "operationId": "GetTrip",
        "parameters": [
          {
            "name": "trip_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique identifier for the trip to retrieve"
          },
          {
            "name": "include_locations",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include the full location history in the response. Use with caution for trips with many location points."
          },
          {
            "name": "include_events",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include driving events (harsh braking, acceleration, etc.) in the response"
          },
          {
            "name": "analytics_level",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Level of analytics detail to include. Options: \"basic\", \"standard\", \"detailed\""
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the trip"
                    },
                    "organization_id": {
                      "type": "string",
                      "description": "Organization that owns this trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle associated with the trip"
                    },
                    "driver_id": {
                      "type": "string",
                      "description": "Driver associated with the trip (if assigned)"
                    },
                    "status": {
                      "type": "string",
                      "description": "Current trip status: \"active\", \"completed\", \"cancelled\", \"interrupted\""
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the trip started"
                    },
                    "end_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the trip ended (null for active trips)"
                    },
                    "locations": {
                      "type": "array",
                      "description": "Array of location points (only included if include_locations=true)\n  \n  \n    \n      Latitude coordinate"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Longitude coordinate"
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "ISO 8601 timestamp of the location point"
                    },
                    "speed_kmh": {
                      "type": "number",
                      "description": "Speed at this location in km/h"
                    },
                    "heading": {
                      "type": "number",
                      "description": "Direction of travel in degrees (0-360)"
                    },
                    "analytics": {
                      "type": "object",
                      "description": "Trip analytics and performance metrics\n  \n  \n    \n      Total distance traveled"
                    },
                    "duration_minutes": {
                      "type": "number",
                      "description": "Trip duration in minutes"
                    },
                    "avg_speed_kmh": {
                      "type": "number",
                      "description": "Average speed for the trip"
                    },
                    "max_speed_kmh": {
                      "type": "number",
                      "description": "Maximum speed reached"
                    },
                    "safety_score": {
                      "type": "integer",
                      "description": "Safety score from 0-100"
                    },
                    "eco_score": {
                      "type": "integer",
                      "description": "Eco-driving score from 0-100"
                    },
                    "events_summary": {
                      "type": "object",
                      "description": "Summary of driving events detected"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/vehicles/{vehicleId}/trips/active": {
      "get": {
        "summary": "Get Vehicle Active Trips",
        "description": "Retrieve all currently active trips (recording or paused) for a specific vehicle",
        "operationId": "GetVehicleActiveTrips",
        "parameters": [
          {
            "name": "vehicleId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the vehicle whose active trips you want to retrieve"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates if the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Response data object\n  \n    \n      Array of active trip objects\n      \n        \n          Unique identifier for the trip"
                    },
                    "org_id": {
                      "type": "string",
                      "description": "Organization ID associated with this trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle ID associated with this trip"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User ID associated with this trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status: \"recording\" or \"paused\""
                    },
                    "purpose": {
                      "type": "string",
                      "description": "Trip purpose: \"personal\", \"business\", \"commute\", \"errand\""
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip started"
                    },
                    "duration_seconds": {
                      "type": "number",
                      "description": "Trip duration in seconds (null if not yet calculated)"
                    },
                    "distance_meters": {
                      "type": "number",
                      "description": "Distance traveled in meters (null if not yet calculated)"
                    },
                    "created_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip was created"
                    },
                    "count": {
                      "type": "number",
                      "description": "Total number of active trips returned"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/vehicles/{vehicleId}/trips/history": {
      "get": {
        "summary": "Get Vehicle Trip History",
        "description": "Retrieve completed trip history for a specific vehicle with optional status filtering",
        "operationId": "GetVehicleTripHistory",
        "parameters": [
          {
            "name": "vehicleId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the vehicle whose trip history you want to retrieve"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter trips by status. If not provided, defaults to \"completed\". Valid values: \"completed\", \"cancelled\", \"recording\", \"paused\""
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates if the request was successful"
                    },
                    "data": {
                      "type": "object",
                      "description": "Response data object\n  \n    \n      Array of trip objects\n      \n        \n          Unique identifier for the trip"
                    },
                    "org_id": {
                      "type": "string",
                      "description": "Organization ID associated with this trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle ID associated with this trip"
                    },
                    "user_id": {
                      "type": "string",
                      "description": "User ID associated with this trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status: \"completed\", \"cancelled\", \"recording\", \"paused\""
                    },
                    "purpose": {
                      "type": "string",
                      "description": "Trip purpose: \"personal\", \"business\", \"commute\", \"errand\""
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip started"
                    },
                    "end_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip ended (null for incomplete trips)"
                    },
                    "duration_seconds": {
                      "type": "number",
                      "description": "Trip duration in seconds (null if not calculated)"
                    },
                    "distance_meters": {
                      "type": "number",
                      "description": "Distance traveled in meters (null if not calculated)"
                    },
                    "created_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when trip was created"
                    },
                    "count": {
                      "type": "number",
                      "description": "Total number of trips returned"
                    },
                    "filter": {
                      "type": "string",
                      "description": "The status filter applied (if any)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/health": {
      "get": {
        "summary": "Trip Service Health Check",
        "description": "Check the health and operational status of the trip management service",
        "operationId": "TripServiceHealthCheck",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "service": {
                      "type": "string",
                      "description": "Service identifier, always \"bookovia-trip-service\""
                    },
                    "status": {
                      "type": "string",
                      "description": "Overall service status: \"healthy\", \"degraded\", or \"unhealthy\""
                    },
                    "timestamp": {
                      "type": "string",
                      "description": "ISO 8601 timestamp of the health check"
                    },
                    "version": {
                      "type": "string",
                      "description": "Current service version"
                    },
                    "uptime_seconds": {
                      "type": "number",
                      "description": "Service uptime in seconds"
                    },
                    "database": {
                      "type": "object",
                      "description": "Database connection status\n  \n    \n      Database status: \"connected\", \"disconnected\", \"slow\""
                    },
                    "response_time_ms": {
                      "type": "number",
                      "description": "Database response time in milliseconds"
                    },
                    "active_connections": {
                      "type": "number",
                      "description": "Number of active database connections"
                    },
                    "active_trips": {
                      "type": "object",
                      "description": "Current active trip statistics\n  \n    \n      Total number of active trips across all organizations"
                    },
                    "organization_count": {
                      "type": "number",
                      "description": "Number of organizations with active trips"
                    },
                    "avg_duration_minutes": {
                      "type": "number",
                      "description": "Average duration of currently active trips"
                    },
                    "performance": {
                      "type": "object",
                      "description": "Service performance metrics\n  \n    \n      Average API requests per minute (last 5 minutes)"
                    },
                    "avg_response_time_ms": {
                      "type": "number",
                      "description": "Average response time in milliseconds"
                    },
                    "error_rate_percent": {
                      "type": "number",
                      "description": "Error rate percentage (last hour)"
                    },
                    "dependencies": {
                      "type": "object",
                      "description": "External service dependencies status\n  \n    \n      Supabase database status"
                    },
                    "redis_cache": {
                      "type": "string",
                      "description": "Redis cache status"
                    },
                    "location_service": {
                      "type": "string",
                      "description": "Location processing service status"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips": {
      "get": {
        "summary": "List Trips",
        "description": "Retrieve a list of trips with filtering, pagination, and sorting options",
        "operationId": "ListTrips",
        "parameters": [
          {
            "name": "organization_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter trips by organization ID (defaults to your authenticated organization)"
          },
          {
            "name": "vehicle_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter trips for a specific vehicle"
          },
          {
            "name": "driver_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter trips for a specific driver"
          },
          {
            "name": "status",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter by trip status. Options: \"active\", \"completed\", \"cancelled\", \"interrupted\""
          },
          {
            "name": "start_date",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter trips starting after this date (ISO 8601 format)"
          },
          {
            "name": "end_date",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Filter trips starting before this date (ISO 8601 format)"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer"
            },
            "description": "Number of trips to return per page (max 200)"
          },
          {
            "name": "cursor",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Cursor for pagination (returned in previous response)"
          },
          {
            "name": "sort",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Sort field. Options: \"start_time\", \"end_time\", \"distance\", \"duration\", \"safety_score\""
          },
          {
            "name": "order",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Sort order. Options: \"asc\", \"desc\""
          },
          {
            "name": "include_analytics",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean"
            },
            "description": "Whether to include basic analytics for each trip"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trips": {
                      "type": "array",
                      "description": "Array of trip objects matching the filter criteria\n  \n  \n    \n      Unique identifier for the trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle associated with the trip"
                    },
                    "driver_id": {
                      "type": "string",
                      "description": "Driver associated with the trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Current trip status"
                    },
                    "start_time": {
                      "type": "string",
                      "description": "Trip start timestamp"
                    },
                    "end_time": {
                      "type": "string",
                      "description": "Trip end timestamp (null for active trips)"
                    },
                    "analytics": {
                      "type": "object",
                      "description": "Basic trip analytics (if include_analytics=true)"
                    },
                    "pagination": {
                      "type": "object",
                      "description": "Pagination information for navigating results\n  \n  \n    \n      Total number of trips matching filters"
                    },
                    "limit": {
                      "type": "integer",
                      "description": "Number of results per page"
                    },
                    "has_more": {
                      "type": "boolean",
                      "description": "Whether there are more results available"
                    },
                    "next_cursor": {
                      "type": "string",
                      "description": "Cursor for the next page (null if no more results)"
                    },
                    "prev_cursor": {
                      "type": "string",
                      "description": "Cursor for the previous page (null if on first page)"
                    },
                    "filters_applied": {
                      "type": "object",
                      "description": "Summary of the filters that were applied to this query"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{sessionId}/pause": {
      "post": {
        "summary": "Pause Trip",
        "description": "Temporarily pause an active trip to stop location tracking and data collection",
        "operationId": "PauseTrip",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the trip session to pause. This is the trip ID returned from the Start Trip endpoint."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates if the trip was successfully paused"
                    },
                    "trip_id": {
                      "type": "string",
                      "description": "The unique identifier for the paused trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status, will be \"paused\""
                    },
                    "paused_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the trip was paused"
                    },
                    "duration_before_pause": {
                      "type": "number",
                      "description": "Duration in seconds from trip start to pause"
                    },
                    "distance_before_pause": {
                      "type": "number",
                      "description": "Distance traveled in kilometers before pause"
                    },
                    "pause_location": {
                      "type": "object",
                      "description": "Location where the trip was paused\n  \n    \n      Latitude coordinate of pause location"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Longitude coordinate of pause location"
                    },
                    "address": {
                      "type": "string",
                      "description": "Address of pause location"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "location": {
                    "type": "object",
                    "description": "**Required**: Current location when pausing the trip. Location data is mandatory to ensure accurate trip event tracking.\n  \n    \n      Current latitude coordinate (-90 to 90)"
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Current longitude coordinate (-180 to 180)"
                  },
                  "address": {
                    "type": "string",
                    "description": "Human-readable address of pause location. If not provided, the address will be automatically geocoded from the coordinates."
                  },
                  "reason": {
                    "type": "string",
                    "description": "Optional reason for pausing the trip (e.g., \"fuel_stop\", \"rest_break\", \"traffic_delay\")"
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Additional custom metadata about the pause event"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{sessionId}/resume": {
      "post": {
        "summary": "Resume Trip",
        "description": "Resume a paused trip to continue location tracking and data collection",
        "operationId": "ResumeTrip",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The unique identifier for the paused trip session to resume. This is the trip ID returned from the Start Trip endpoint."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Indicates if the trip was successfully resumed"
                    },
                    "trip_id": {
                      "type": "string",
                      "description": "The unique identifier for the resumed trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status, will be \"active\""
                    },
                    "resumed_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the trip was resumed"
                    },
                    "total_pause_duration": {
                      "type": "number",
                      "description": "Total time in seconds the trip was paused"
                    },
                    "pause_count": {
                      "type": "number",
                      "description": "Number of times this trip has been paused/resumed"
                    },
                    "resume_location": {
                      "type": "object",
                      "description": "Location where the trip was resumed\n  \n    \n      Latitude coordinate of resume location"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Longitude coordinate of resume location"
                    },
                    "address": {
                      "type": "string",
                      "description": "Address of resume location"
                    },
                    "distance_from_pause": {
                      "type": "number",
                      "description": "Distance in kilometers between pause and resume locations"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "location": {
                    "type": "object",
                    "description": "**Required**: Current location when resuming the trip. Location data is mandatory to ensure accurate trip event tracking.\n  \n    \n      Current latitude coordinate (-90 to 90)"
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Current longitude coordinate (-180 to 180)"
                  },
                  "address": {
                    "type": "string",
                    "description": "Human-readable address of resume location. If not provided, the address will be automatically geocoded from the coordinates."
                  },
                  "reason": {
                    "type": "string",
                    "description": "Optional reason for resuming (e.g., \"fuel_complete\", \"break_ended\", \"maintenance_finished\")"
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Additional custom metadata about the resume event"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/start": {
      "post": {
        "summary": "Start Trip",
        "description": "Create and start a new vehicle trip to begin tracking location data and analytics",
        "operationId": "StartTrip",
        "parameters": [],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the created trip. Use this ID for all subsequent trip operations."
                    },
                    "organization_id": {
                      "type": "string",
                      "description": "Organization identifier that owns this trip"
                    },
                    "vehicle_id": {
                      "type": "string",
                      "description": "Vehicle identifier associated with the trip"
                    },
                    "driver_id": {
                      "type": "string",
                      "description": "Driver identifier associated with the trip (if provided)"
                    },
                    "status": {
                      "type": "string",
                      "description": "Current trip status. Will be \"active\" for newly created trips."
                    },
                    "start_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the trip was started"
                    },
                    "start_location": {
                      "type": "object",
                      "description": "Starting location information\n  \n  \n    \n      Starting latitude coordinate"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Starting longitude coordinate"
                    },
                    "address": {
                      "type": "string",
                      "description": "Resolved address for the starting location"
                    },
                    "metadata": {
                      "type": "object",
                      "description": "Custom metadata provided during trip creation"
                    },
                    "analytics": {
                      "type": "object",
                      "description": "Initial analytics object (mostly null/zero values for new trips)\n  \n  \n    \n      Total distance traveled (0 for new trips)"
                    },
                    "duration_minutes": {
                      "type": "number",
                      "description": "Trip duration in minutes (0 for new trips)"
                    },
                    "max_speed_kmh": {
                      "type": "number",
                      "description": "Maximum speed reached (null for new trips)"
                    },
                    "avg_speed_kmh": {
                      "type": "number",
                      "description": "Average speed (null for new trips)"
                    },
                    "safety_score": {
                      "type": "integer",
                      "description": "Safety score from 0-100 (null until location data is available)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "vehicle_id": {
                    "type": "string",
                    "description": "Unique identifier for the vehicle. Must be a valid vehicle ID associated with your organization."
                  },
                  "driver_id": {
                    "type": "string",
                    "description": "Unique identifier for the driver. If not provided, the trip will be created without a driver association."
                  },
                  "start_location": {
                    "type": "object",
                    "description": "Manual start location for the trip. If not provided, the location will be automatically detected from the first GPS point uploaded.\n  \n  \n    \n      Latitude coordinate in decimal degrees (-90 to 90)"
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Longitude coordinate in decimal degrees (-180 to 180)"
                  },
                  "address": {
                    "type": "string",
                    "description": "Human-readable address for the location. If not provided, the address will be automatically geocoded from the coordinates using Mapbox Geocoding API."
                  },
                  "metadata": {
                    "type": "object",
                    "description": "Custom metadata for the trip. Can include any JSON-serializable data relevant to your application.\n  \n  \n    \n      Purpose of the trip (e.g., \"delivery\", \"service\", \"personal\")"
                  },
                  "route_name": {
                    "type": "string",
                    "description": "Name or identifier for the planned route"
                  },
                  "customer_id": {
                    "type": "string",
                    "description": "Customer identifier for delivery or service trips"
                  },
                  "priority": {
                    "type": "string",
                    "description": "Trip priority level (e.g., \"low\", \"normal\", \"high\", \"urgent\")"
                  },
                  "expected_duration_minutes": {
                    "type": "integer",
                    "description": "Expected trip duration in minutes"
                  },
                  "planned_distance_km": {
                    "type": "number",
                    "description": "Planned trip distance in kilometers"
                  },
                  "odometer_reading": {
                    "type": "integer",
                    "description": "Vehicle odometer reading at trip start (in kilometers or miles based on your organization settings)"
                  },
                  "fuel_level_percent": {
                    "type": "number",
                    "description": "Fuel level percentage at trip start (0-100)"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{trip_id}/stop": {
      "post": {
        "summary": "Stop Trip",
        "description": "Stop an active trip and finalize tracking data with comprehensive analytics",
        "operationId": "StopTrip",
        "parameters": [
          {
            "name": "trip_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique identifier for the trip to stop. Must be an active trip associated with your organization."
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the stopped trip"
                    },
                    "status": {
                      "type": "string",
                      "description": "Trip status, will be \"completed\", \"cancelled\", or \"interrupted\""
                    },
                    "end_time": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the trip was stopped"
                    },
                    "end_location": {
                      "type": "object",
                      "description": "Final location information\n  \n  \n    \n      Ending latitude coordinate"
                    },
                    "longitude": {
                      "type": "number",
                      "description": "Ending longitude coordinate"
                    },
                    "address": {
                      "type": "string",
                      "description": "Resolved address for the ending location"
                    },
                    "analytics": {
                      "type": "object",
                      "description": "Comprehensive trip analytics and performance metrics\n  \n  \n    \n      Total distance traveled in kilometers"
                    },
                    "duration_minutes": {
                      "type": "number",
                      "description": "Total trip duration in minutes"
                    },
                    "max_speed_kmh": {
                      "type": "number",
                      "description": "Maximum speed reached during the trip"
                    },
                    "avg_speed_kmh": {
                      "type": "number",
                      "description": "Average speed for the entire trip"
                    },
                    "idle_time_minutes": {
                      "type": "number",
                      "description": "Total time spent idling (speed < 5 km/h)"
                    },
                    "safety_score": {
                      "type": "integer",
                      "description": "Overall safety score from 0-100 based on driving behavior"
                    },
                    "eco_score": {
                      "type": "integer",
                      "description": "Eco-friendly driving score from 0-100"
                    },
                    "harsh_events": {
                      "type": "object",
                      "description": "Count of harsh driving events detected"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "end_location": {
                    "type": "object",
                    "description": "Manual end location for the trip. If not provided, the location will be automatically detected from the last GPS point uploaded.\n  \n  \n    \n      Latitude coordinate in decimal degrees (-90 to 90)"
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Longitude coordinate in decimal degrees (-180 to 180)"
                  },
                  "address": {
                    "type": "string",
                    "description": "Human-readable address for the location"
                  },
                  "odometer_reading": {
                    "type": "integer",
                    "description": "Vehicle odometer reading at trip end (in kilometers or miles based on your organization settings)"
                  },
                  "fuel_level_percent": {
                    "type": "number",
                    "description": "Fuel level percentage at trip end (0-100)"
                  },
                  "completion_status": {
                    "type": "string",
                    "description": "Status indicating how the trip was completed. Options: \"completed\", \"cancelled\", \"interrupted\""
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{trip_id}/metadata": {
      "put": {
        "summary": "Update Trip Metadata",
        "description": "Update custom metadata and properties for an existing trip",
        "operationId": "UpdateTripMetadata",
        "parameters": [
          {
            "name": "trip_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Unique identifier for the trip to update"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "trip_id": {
                      "type": "string",
                      "description": "Unique identifier for the updated trip"
                    },
                    "metadata": {
                      "type": "object",
                      "description": "Complete updated metadata object after the merge/replacement"
                    },
                    "updated_at": {
                      "type": "string",
                      "description": "ISO 8601 timestamp when the metadata was last updated"
                    },
                    "metadata_history": {
                      "type": "array",
                      "description": "Array of metadata change records (if audit logging is enabled)\n  \n  \n    \n      When the change was made"
                    },
                    "changed_by": {
                      "type": "string",
                      "description": "API key or user that made the change"
                    },
                    "changes": {
                      "type": "object",
                      "description": "Summary of fields that were modified"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "metadata": {
                    "type": "object",
                    "description": "Custom metadata object to merge with existing metadata. Use null values to remove fields.\n  \n  \n    \n      Trip purpose: \"delivery\", \"service\", \"personal\", \"commute\", \"emergency\""
                  },
                  "route_name": {
                    "type": "string",
                    "description": "Name or identifier for the route"
                  },
                  "customer_id": {
                    "type": "string",
                    "description": "Customer identifier for service/delivery trips"
                  },
                  "work_order_id": {
                    "type": "string",
                    "description": "Work order or job identifier"
                  },
                  "priority": {
                    "type": "string",
                    "description": "Trip priority: \"low\", \"normal\", \"high\", \"urgent\""
                  },
                  "driver_notes": {
                    "type": "string",
                    "description": "Driver notes or comments about the trip"
                  },
                  "tags": {
                    "type": "array",
                    "description": "Array of string tags for categorization"
                  },
                  "cost_center": {
                    "type": "string",
                    "description": "Cost center or department for accounting"
                  },
                  "external_id": {
                    "type": "string",
                    "description": "External system identifier for integration"
                  },
                  "replace_metadata": {
                    "type": "boolean",
                    "description": "If true, completely replace existing metadata instead of merging. Use with caution."
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{sessionId}/time": {
      "patch": {
        "summary": "Update Trip Time",
        "description": "Correct the start_time and/or end_time of a completed or paused trip. Useful for manual or backdated trip entry. Blocked on trips with status `recording`. Automatically recalculates `duration_seconds` when both times are known after the update.",
        "operationId": "UpdateTripTime",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Unique identifier for the trip to update"
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "start_time": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Corrected trip start time in ISO 8601 format (e.g. `2026-11-22T08:00:00Z`). Optional — omit to leave unchanged."
                  },
                  "end_time": {
                    "type": "string",
                    "format": "date-time",
                    "description": "Corrected trip end time in ISO 8601 format (e.g. `2026-11-22T09:30:00Z`). Must be after `start_time`. Optional — omit to leave unchanged."
                  }
                }
              },
              "example": {
                "start_time": "2026-11-22T08:00:00Z",
                "end_time": "2026-11-22T09:30:00Z"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Trip time updated successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "trip_id": {
                      "type": "string",
                      "format": "uuid",
                      "description": "Unique identifier of the updated trip"
                    },
                    "start_time": {
                      "type": "string",
                      "format": "date-time",
                      "description": "Updated trip start time"
                    },
                    "end_time": {
                      "type": "string",
                      "format": "date-time",
                      "description": "Updated trip end time"
                    },
                    "duration_seconds": {
                      "type": "integer",
                      "description": "Recalculated trip duration in seconds (null if either time is not set)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request — no fields provided, end_time not after start_time, or trip is currently recording",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "404": {
            "description": "Trip not found",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/trips/{sessionId}/gps/batch": {
      "post": {
        "summary": "Upload GPS Batch",
        "description": "Upload batch GPS location points with sensor data for real-time tracking and analytics",
        "operationId": "UploadGPSBatch",
        "parameters": [
          {
            "name": "sessionId",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "The trip ID returned from the Start Trip endpoint"
          }
        ],
        "responses": {
          "200": {
            "description": "Successful response",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "description": "Whether the upload was successful"
                    },
                    "trip_id": {
                      "type": "string",
                      "description": "The trip ID that received the GPS points"
                    },
                    "points_saved": {
                      "type": "integer",
                      "description": "Number of points successfully saved"
                    },
                    "storage": {
                      "type": "string",
                      "description": "Storage destinations where data was written (e.g., \"duckdb_parquet\")"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ErrorResponse"
                }
              }
            }
          }
        },
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "driver_id": {
                    "type": "string",
                    "description": "Driver identifier (optional, extracted from trip if not provided)"
                  },
                  "vehicle_id": {
                    "type": "string",
                    "description": "Vehicle identifier (optional, extracted from trip if not provided)"
                  },
                  "points": {
                    "type": "array",
                    "description": "Array of GPS location points with enterprise sensor data (maximum 100 points per request)\n  \n  \n    \n    ### Core Position (Required)\n    \n      Latitude coordinate in decimal degrees (-90 to 90)"
                  },
                  "longitude": {
                    "type": "number",
                    "description": "Longitude coordinate in decimal degrees (-180 to 180)"
                  },
                  "speed": {
                    "type": "number",
                    "description": "Speed in meters per second (m/s)"
                  },
                  "accuracy": {
                    "type": "number",
                    "description": "GPS accuracy radius in meters"
                  },
                  "recorded_at": {
                    "type": "string",
                    "description": "ISO 8601 timestamp when the GPS point was recorded"
                  },
                  "altitude": {
                    "type": "number",
                    "description": "GPS altitude in meters above sea level"
                  },
                  "heading": {
                    "type": "number",
                    "description": "Heading/bearing in degrees (0-360, where 0 is North)"
                  },
                  "acceleration_x": {
                    "type": "number",
                    "description": "Accelerometer X-axis in m/s² (lateral acceleration)"
                  },
                  "acceleration_y": {
                    "type": "number",
                    "description": "Accelerometer Y-axis in m/s² (longitudinal acceleration)"
                  },
                  "acceleration_z": {
                    "type": "number",
                    "description": "Accelerometer Z-axis in m/s² (vertical acceleration)"
                  },
                  "g_force_magnitude": {
                    "type": "number",
                    "description": "Calculated G-force magnitude for crash detection (G-force > 3.0 = potential crash)"
                  },
                  "rotation_x": {
                    "type": "number",
                    "description": "Gyroscope pitch in rad/s. Detects phone tilting (distracted driving indicator)"
                  },
                  "rotation_y": {
                    "type": "number",
                    "description": "Gyroscope roll in rad/s. Detects phone rolling (crash indicator)"
                  },
                  "rotation_z": {
                    "type": "number",
                    "description": "Gyroscope yaw in rad/s. Detects phone rotation (handling while driving)"
                  },
                  "magnetic_x": {
                    "type": "number",
                    "description": "Magnetometer X-axis in μT (microtesla)"
                  },
                  "magnetic_y": {
                    "type": "number",
                    "description": "Magnetometer Y-axis in μT"
                  },
                  "magnetic_z": {
                    "type": "number",
                    "description": "Magnetometer Z-axis in μT"
                  },
                  "magnetic_bearing": {
                    "type": "number",
                    "description": "True compass bearing in degrees (independent of GPS)"
                  },
                  "pressure": {
                    "type": "number",
                    "description": "Barometric pressure in hPa (hectopascals). More accurate than GPS altitude"
                  },
                  "pressure_altitude": {
                    "type": "number",
                    "description": "Calculated altitude from pressure in meters"
                  },
                  "satellite_count": {
                    "type": "integer",
                    "description": "Number of GPS satellites in view. Less than 4 satellites = poor quality"
                  },
                  "hdop": {
                    "type": "number",
                    "description": "Horizontal Dilution of Precision. Lower is better (Less than 2.0 = excellent)"
                  },
                  "vdop": {
                    "type": "number",
                    "description": "Vertical Dilution of Precision. Lower is better"
                  },
                  "location_provider": {
                    "type": "string",
                    "description": "GPS provider: \"gps\", \"network\", \"fused\". \"gps\" is most accurate"
                  },
                  "is_mocked": {
                    "type": "boolean",
                    "description": "True if location is mocked/spoofed (fraud detection). Rejects fake GPS apps"
                  },
                  "activity": {
                    "type": "string",
                    "description": "Detected activity: \"driving\", \"walking\", \"running\", \"cycling\", \"still\", \"unknown\""
                  },
                  "activity_confidence": {
                    "type": "integer",
                    "description": "Activity confidence level (0-100). Values greater than 75 are reliable"
                  },
                  "battery_level": {
                    "type": "integer",
                    "description": "Device battery level percentage (0-100)"
                  },
                  "battery_temp": {
                    "type": "number",
                    "description": "Battery temperature in Celsius. High temp (greater than 40°C) = overheating risk"
                  },
                  "is_charging": {
                    "type": "boolean",
                    "description": "True if device is charging. Indicates phone is mounted properly"
                  },
                  "is_screen_on": {
                    "type": "boolean",
                    "description": "True if screen is on. Distracted driving indicator when moving"
                  },
                  "app_in_foreground": {
                    "type": "boolean",
                    "description": "True if app is in foreground. False = backgrounded"
                  },
                  "light_level": {
                    "type": "number",
                    "description": "Ambient light in lux. Less than 10 lux = night driving (3x crash risk)"
                  },
                  "noise_level": {
                    "type": "number",
                    "description": "Ambient noise in decibels (dB). Greater than 100 dB = crash/impact detected"
                  },
                  "is_call_active": {
                    "type": "boolean",
                    "description": "True if phone call is active while driving"
                  },
                  "touch_count": {
                    "type": "integer",
                    "description": "Number of screen touches in the last second. Greater than 5 touches/minute = distraction"
                  },
                  "network_type": {
                    "type": "string",
                    "description": "Network type: \"5G\", \"LTE\", \"3G\", \"WiFi\", \"offline\""
                  },
                  "wifi_ssid": {
                    "type": "string",
                    "description": "Connected WiFi network name. Used for indoor geofencing"
                  },
                  "wifi_strength": {
                    "type": "integer",
                    "description": "WiFi signal strength in dBm. Greater than -50 dBm = excellent"
                  },
                  "bluetooth_devices": {
                    "type": "array",
                    "description": "Array of connected Bluetooth device names. Detects car audio, OBD-II adapters"
                  },
                  "step_count": {
                    "type": "integer",
                    "description": "Cumulative step count. Detects when driver exits vehicle"
                  },
                  "engine_rpm": {
                    "type": "integer",
                    "description": "Engine RPM from OBD-II adapter. Aggressive driving indicator"
                  },
                  "throttle_pos": {
                    "type": "number",
                    "description": "Throttle position (0-100%). High values = aggressive acceleration"
                  },
                  "engine_load": {
                    "type": "number",
                    "description": "Engine load percentage (0-100%). High load = stress on vehicle"
                  },
                  "fuel_level": {
                    "type": "number",
                    "description": "Fuel level percentage (0-100%) from vehicle ECU"
                  },
                  "coolant_temp": {
                    "type": "number",
                    "description": "Engine coolant temperature in Celsius. Greater than 100°C = overheating"
                  }
                }
              }
            }
          }
        },
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "tags": [
          "trips"
        ]
      }
    },
    "/payments/create-intent": {
      "post": {
        "summary": "Create Payment Intent (Booking)",
        "description": "Creates a Stripe payment intent for scheduled bookings using the ESCROW pattern. Funds are held on the platform until service completion, then transferred to the provider after a 48-hour hold period. Supports BNPL payment methods (Klarna, Affirm, Afterpay).",
        "operationId": "CreatePaymentIntent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "providerId",
                  "currency"
                ],
                "properties": {
                  "serviceId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Single service ID (legacy support)"
                  },
                  "serviceIds": {
                    "type": "array",
                    "items": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "description": "Multiple service IDs for cart checkout"
                  },
                  "providerId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Provider UUID (must be verified on Stripe)"
                  },
                  "currency": {
                    "type": "string",
                    "default": "usd",
                    "description": "Payment currency code (ISO 4217)"
                  },
                  "bookingId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Existing booking ID (optional)"
                  },
                  "reservationId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Reservation ID to convert to booking"
                  },
                  "vehicleType": {
                    "type": "string",
                    "description": "Vehicle type for pricing calculation"
                  },
                  "shippingAddress": {
                    "type": "object",
                    "required": [
                      "name",
                      "address"
                    ],
                    "description": "Required for BNPL payment methods",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "phone": {
                        "type": "string"
                      },
                      "address": {
                        "type": "object",
                        "required": [
                          "line1",
                          "city",
                          "state",
                          "postal_code",
                          "country"
                        ],
                        "properties": {
                          "line1": {
                            "type": "string"
                          },
                          "line2": {
                            "type": "string"
                          },
                          "city": {
                            "type": "string"
                          },
                          "state": {
                            "type": "string"
                          },
                          "postal_code": {
                            "type": "string"
                          },
                          "country": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Payment intent created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "clientSecret": {
                      "type": "string",
                      "description": "Stripe client secret for payment confirmation (use with Stripe SDK)"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request (missing required fields)"
          },
          "401": {
            "description": "Unauthorized (invalid JWT token)"
          },
          "404": {
            "description": "Provider not found or not verified on Stripe"
          },
          "500": {
            "description": "Internal server error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "payments"
        ]
      }
    },
    "/payments/create-invoice-intent": {
      "post": {
        "summary": "Create Payment Intent (Invoice)",
        "description": "Creates a Stripe payment intent for custom service requests/invoices (add-ons, upgrades). Uses the same ESCROW pattern as booking payments. Updates custom service request status to payment_pending.",
        "operationId": "CreateInvoicePaymentIntent",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "serviceId",
                  "providerId",
                  "currency",
                  "custom_service_request_id"
                ],
                "properties": {
                  "serviceId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Service ID for the invoice"
                  },
                  "providerId": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Provider UUID"
                  },
                  "currency": {
                    "type": "string",
                    "default": "usd",
                    "description": "Payment currency code"
                  },
                  "custom_service_request_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Custom service request ID"
                  },
                  "parent_booking_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "Optional: Parent booking ID if this is an add-on"
                  },
                  "shippingAddress": {
                    "type": "object",
                    "description": "Required for BNPL payment methods",
                    "properties": {
                      "name": {
                        "type": "string"
                      },
                      "phone": {
                        "type": "string"
                      },
                      "address": {
                        "type": "object",
                        "required": [
                          "line1",
                          "city",
                          "state",
                          "postal_code",
                          "country"
                        ],
                        "properties": {
                          "line1": {
                            "type": "string"
                          },
                          "line2": {
                            "type": "string"
                          },
                          "city": {
                            "type": "string"
                          },
                          "state": {
                            "type": "string"
                          },
                          "postal_code": {
                            "type": "string"
                          },
                          "country": {
                            "type": "string"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Invoice payment intent created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "clientSecret": {
                      "type": "string",
                      "description": "Stripe client secret for payment confirmation"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Bad request (missing custom_service_request_id)"
          },
          "401": {
            "description": "Unauthorized (invalid JWT token)"
          },
          "404": {
            "description": "Provider not found or not verified on Stripe"
          },
          "500": {
            "description": "Internal server error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "payments"
        ]
      }
    },
    "/admin/payments/trigger-escrow-transfer/booking": {
      "post": {
        "summary": "Trigger Escrow Transfer for Booking (Admin)",
        "description": "Manually triggers the 48-hour escrow transfer workflow for a completed booking. Used for webhooks, database triggers, admin panels, or recovery scenarios. Idempotent - returns error if workflow already running.",
        "operationId": "TriggerBookingEscrowTransfer",
        "tags": ["payments", "admin"],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["booking_id"],
                "properties": {
                  "booking_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "UUID of the completed booking",
                    "example": "550e8400-e29b-41d4-a716-446655440000"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Escrow transfer workflow started successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "Escrow transfer workflow started for booking 550e8400-e29b-41d4-a716-446655440000"
                    },
                    "workflow_id": {
                      "type": "string",
                      "example": "escrow-transfer-pi_3QRs7wKX4eC1N2xY0Z9876543"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request body"
          },
          "404": {
            "description": "Booking not found, not completed, or has no payment"
          },
          "409": {
            "description": "Transfer workflow already completed for this payment"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/admin/payments/trigger-escrow-transfer/custom-service": {
      "post": {
        "summary": "Trigger Escrow Transfer for Custom Service (Admin)",
        "description": "Manually triggers the 48-hour escrow transfer workflow for a completed custom service request (invoice payment). Used for webhooks, database triggers, admin panels, or recovery scenarios. Idempotent - returns error if workflow already running.",
        "operationId": "TriggerCustomServiceEscrowTransfer",
        "tags": ["payments", "admin"],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["custom_service_request_id"],
                "properties": {
                  "custom_service_request_id": {
                    "type": "string",
                    "format": "uuid",
                    "description": "UUID of the completed custom service request",
                    "example": "660e9511-f30c-52e5-b827-557766551111"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Escrow transfer workflow started successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "Escrow transfer workflow started for custom service request 660e9511-f30c-52e5-b827-557766551111"
                    },
                    "workflow_id": {
                      "type": "string",
                      "example": "escrow-transfer-pi_3QRs7wKX4eC1N2xY0Z9876543"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request body"
          },
          "404": {
            "description": "Custom service request not found, not completed, or has no payment"
          },
          "409": {
            "description": "Transfer workflow already completed for this payment"
          },
          "500": {
            "description": "Internal server error"
          }
        }
      }
    },
    "/admin/payments/backfill-escrow-transfers": {
      "post": {
        "summary": "Backfill Escrow Transfers (Admin)",
        "description": "Batch processes all completed bookings to start escrow transfer workflows. Used for initial deployment, system recovery, or processing historical data. Skips workflows that are already running or completed. Returns counts of successful, skipped, and failed transfers.",
        "operationId": "BackfillEscrowTransfers",
        "tags": ["payments", "admin"],
        "security": [
          {
            "ApiKeyAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "hours_ago_limit": {
                    "type": "integer",
                    "description": "Only process bookings completed within last N hours (0 = all time)",
                    "example": 48,
                    "default": 48
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Backfill completed",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "success": {
                      "type": "boolean",
                      "example": true
                    },
                    "message": {
                      "type": "string",
                      "example": "Backfill completed for last 48 hours"
                    },
                    "success_count": {
                      "type": "integer",
                      "description": "Number of workflows started successfully",
                      "example": 42
                    },
                    "skipped_count": {
                      "type": "integer",
                      "description": "Number of workflows skipped (already running/completed)",
                      "example": 15
                    },
                    "error_count": {
                      "type": "integer",
                      "description": "Number of workflows that failed to start",
                      "example": 2
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Backfill operation failed"
          }
        }
      }
    },
    "/vehicles/add-vehicle": {
      "post": {
        "tags": [
          "Vehicles"
        ],
        "summary": "Add a vehicle",
        "description": "Add a vehicle by VIN or license plate lookup (requires authentication)",
        "operationId": "AddVehicle",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/AddVehicleRequest"
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Vehicle added successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/AddVehicleResponse"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or VIN"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/vehicles/{id}": {
      "delete": {
        "tags": [
          "Vehicles"
        ],
        "summary": "Delete a vehicle",
        "description": "Delete a vehicle (requires authentication). If the deleted vehicle was the default, another vehicle will automatically be set as default.",
        "operationId": "DeleteVehicle",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Vehicle ID to delete"
          }
        ],
        "responses": {
          "200": {
            "description": "Vehicle deleted successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Vehicle deleted successfully"
                    },
                    "deleted_vehicle": {
                      "type": "object",
                      "properties": {
                        "id": {
                          "type": "string"
                        },
                        "vehicle": {
                          "type": "string",
                          "example": "2020 Honda Accord"
                        },
                        "vin": {
                          "type": "string"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Vehicle not found or you do not own this vehicle"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/vehicles": {
      "get": {
        "tags": [
          "Vehicles"
        ],
        "summary": "List or get vehicles",
        "description": "List all user vehicles or get a specific vehicle by ID (requires authentication). Supports filtering by VIN, default status, and pagination.",
        "operationId": "GetVehicles",
        "parameters": [
          {
            "name": "vehicle_id",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "Vehicle ID to get a single vehicle"
          },
          {
            "name": "vin",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string"
            },
            "description": "VIN filter (partial match, case-insensitive)"
          },
          {
            "name": "is_default",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": [
                "true",
                "false"
              ]
            },
            "description": "Filter by default status"
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 50
            },
            "description": "Pagination limit"
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Pagination offset"
          },
          {
            "name": "include_raw",
            "in": "query",
            "required": false,
            "schema": {
              "type": "boolean",
              "default": false
            },
            "description": "Include raw VPIC data"
          }
        ],
        "responses": {
          "200": {
            "description": "Vehicles list or single vehicle",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "vehicles": {
                      "type": "array",
                      "items": {
                        "type": "object"
                      },
                      "description": "Array of vehicles (when listing)"
                    },
                    "vehicle": {
                      "type": "object",
                      "description": "Single vehicle (when vehicle_id provided)"
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "offset": {
                          "type": "integer"
                        },
                        "limit": {
                          "type": "integer"
                        },
                        "total": {
                          "type": "integer"
                        },
                        "returned": {
                          "type": "integer"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Vehicle not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/vehicles/{id}/make-default": {
      "post": {
        "tags": [
          "Vehicles"
        ],
        "summary": "Make vehicle default",
        "description": "Set a vehicle as the default vehicle. Automatically unsets all other vehicles as default.",
        "operationId": "MakeVehicleDefault",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Vehicle ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Vehicle set as default",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Vehicle set as default successfully"
                    },
                    "vehicle_id": {
                      "type": "string"
                    },
                    "vehicle": {
                      "type": "string",
                      "example": "2020 Honda Accord"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Vehicle not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ]
      }
    },
    "/spend-management/bank-accounts/session": {
      "post": {
        "summary": "Create Stripe Financial Connections Session",
        "description": "Creates a Stripe Financial Connections session for linking bank accounts",
        "operationId": "CreateFCSession",
        "responses": {
          "200": {
            "description": "FC session created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session_id": {
                      "type": "string",
                      "description": "Financial Connections session ID"
                    },
                    "client_secret": {
                      "type": "string",
                      "description": "Client secret for initializing FC on frontend"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Bank Accounts"
        ]
      }
    },
    "/spend-management/bank-accounts": {
      "get": {
        "summary": "Get All Bank Accounts",
        "description": "Retrieves all linked bank accounts for the authenticated user",
        "operationId": "GetBankAccounts",
        "responses": {
          "200": {
            "description": "Bank accounts retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "id": {
                        "type": "string"
                      },
                      "fc_account_id": {
                        "type": "string"
                      },
                      "institution_name": {
                        "type": "string"
                      },
                      "account_type": {
                        "type": "string",
                        "example": "checking"
                      },
                      "status": {
                        "type": "string",
                        "enum": [
                          "pending",
                          "synced",
                          "requires_relink",
                          "inactive"
                        ]
                      },
                      "linked_at": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Bank Accounts"
        ]
      }
    },
    "/spend-management/bank-accounts/{id}": {
      "get": {
        "summary": "Get Bank Account",
        "description": "Retrieves a specific bank account by ID",
        "operationId": "GetBankAccount",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Bank account ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Bank account retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Bank account not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Bank Accounts"
        ]
      },
      "patch": {
        "summary": "Update Bank Account",
        "description": "Updates bank account settings (nickname, auto-categorization)",
        "operationId": "UpdateBankAccount",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Bank account ID"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "nickname": {
                    "type": "string"
                  },
                  "auto_categorization": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bank account updated successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Bank account not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Bank Accounts"
        ]
      },
      "delete": {
        "summary": "Remove Bank Account",
        "description": "Deactivates a bank account (soft delete)",
        "operationId": "RemoveBankAccount",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Bank account ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Bank account removed successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Bank account not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Bank Accounts"
        ]
      }
    },
    "/spend-management/bank-accounts/{id}/sync": {
      "post": {
        "summary": "Trigger Manual Sync",
        "description": "Triggers manual sync for a bank account to fetch latest transactions",
        "operationId": "TriggerSync",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Bank account ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Sync triggered successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Bank account not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Bank Accounts"
        ]
      }
    },
    "/spend-management/connections/types": {
      "get": {
        "summary": "List Connection Types",
        "description": "Get all available integration types (Bank, QuickBooks, Xero, Uber, Gmail, Outlook)",
        "operationId": "ListConnectionTypes",
        "responses": {
          "200": {
            "description": "Connection types retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "$ref": "#/components/schemas/ConnectionType"
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      }
    },
    "/spend-management/connections/types/{type}": {
      "get": {
        "summary": "Get Connection Type Details",
        "description": "Get detailed information about a specific connection type",
        "operationId": "GetConnectionType",
        "parameters": [
          {
            "name": "type",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "enum": ["bank", "quickbooks", "xero", "uber", "gmail", "outlook"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Connection type retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionType"
                }
              }
            }
          },
          "404": {
            "description": "Connection type not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      }
    },
    "/spend-management/connections": {
      "post": {
        "summary": "Create Connection",
        "description": "Initiate a new connection (returns auth URL for OAuth flows or session for bank connections)",
        "operationId": "CreateConnection",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["type_key"],
                "properties": {
                  "type_key": {
                    "type": "string",
                    "enum": ["bank", "quickbooks", "xero", "uber", "gmail", "outlook"]
                  },
                  "display_name": {
                    "type": "string"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "201": {
            "description": "Connection created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionWithType"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      },
      "get": {
        "summary": "List Connections",
        "description": "Get all user connections with optional filtering by type",
        "operationId": "ListConnections",
        "parameters": [
          {
            "name": "type",
            "in": "query",
            "required": false,
            "schema": {
              "type": "string",
              "enum": ["bank", "quickbooks", "xero", "uber", "gmail", "outlook"]
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Connections retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "connections": {
                      "type": "array",
                      "items": {
                        "$ref": "#/components/schemas/ConnectionWithType"
                      }
                    },
                    "summary": {
                      "type": "object",
                      "properties": {
                        "total": {
                          "type": "integer"
                        },
                        "by_type": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "integer"
                          }
                        },
                        "by_status": {
                          "type": "object",
                          "additionalProperties": {
                            "type": "integer"
                          }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      }
    },
    "/spend-management/connections/{id}": {
      "get": {
        "summary": "Get Connection Details",
        "description": "Get detailed information about a specific connection including sync history",
        "operationId": "GetConnection",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Connection retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "$ref": "#/components/schemas/ConnectionDetailResponse"
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Connection not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      },
      "patch": {
        "summary": "Update Connection",
        "description": "Update connection settings like display name or preferences",
        "operationId": "UpdateConnection",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "display_name": {
                    "type": "string"
                  },
                  "is_active": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Connection updated successfully"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Connection not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      },
      "delete": {
        "summary": "Delete Connection",
        "description": "Disconnect and remove a connection",
        "operationId": "DeleteConnection",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Connection deleted successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Connection not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      }
    },
    "/spend-management/connections/{id}/sync": {
      "post": {
        "summary": "Trigger Manual Sync",
        "description": "Trigger a manual data sync for a connection",
        "operationId": "TriggerConnectionSync",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Sync triggered successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Connection not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      }
    },
    "/spend-management/connections/{id}/expenses": {
      "get": {
        "summary": "Get Connection Expenses",
        "description": "Get all expenses from a specific connection",
        "operationId": "GetConnectionExpenses",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            }
          },
          {
            "name": "limit",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 50
            }
          },
          {
            "name": "offset",
            "in": "query",
            "required": false,
            "schema": {
              "type": "integer",
              "default": 0
            }
          }
        ],
        "responses": {
          "200": {
            "description": "Expenses retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "expenses": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "connection_id": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "number"
                          },
                          "currency": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "date": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "category": {
                            "type": "string"
                          },
                          "is_business": {
                            "type": "boolean"
                          }
                        }
                      }
                    },
                    "total": {
                      "type": "integer"
                    },
                    "pagination": {
                      "type": "object",
                      "properties": {
                        "limit": {
                          "type": "integer"
                        },
                        "offset": {
                          "type": "integer"
                        },
                        "has_more": {
                          "type": "boolean"
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Connection not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      }
    },
    "/spend-management/connections/bank/session": {
      "post": {
        "summary": "Create Bank Connection Session",
        "description": "Creates a Stripe Financial Connections session for linking bank accounts (alias for /bank-accounts/session)",
        "operationId": "CreateBankConnectionSession",
        "responses": {
          "200": {
            "description": "FC session created successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "session_id": {
                      "type": "string"
                    },
                    "client_secret": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Connections"
        ]
      }
    },
    "/spend-management/balances": {
      "get": {
        "summary": "Get All Balances",
        "description": "Retrieves current balances for all linked bank accounts",
        "operationId": "GetBalances",
        "responses": {
          "200": {
            "description": "Balances retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "array",
                  "items": {
                    "type": "object",
                    "properties": {
                      "account_id": {
                        "type": "string"
                      },
                      "current_balance": {
                        "type": "number"
                      },
                      "available_balance": {
                        "type": "number"
                      },
                      "currency": {
                        "type": "string",
                        "example": "usd"
                      },
                      "as_of": {
                        "type": "string",
                        "format": "date-time"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Balances"
        ]
      }
    },
    "/spend-management/balances/total": {
      "get": {
        "summary": "Get Total Balance",
        "description": "Retrieves total balance across all linked accounts",
        "operationId": "GetTotalBalance",
        "responses": {
          "200": {
            "description": "Total balance retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "total_current": {
                      "type": "number"
                    },
                    "total_available": {
                      "type": "number"
                    },
                    "currency": {
                      "type": "string",
                      "example": "usd"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Balances"
        ]
      }
    },
    "/spend-management/balances/{account_id}": {
      "get": {
        "summary": "Get Account Balance",
        "description": "Retrieves balance for a specific bank account",
        "operationId": "GetAccountBalance",
        "parameters": [
          {
            "name": "account_id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Bank account ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Account balance retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Account not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Balances"
        ]
      }
    },
    "/spend-management/transactions": {
      "get": {
        "summary": "Get Transactions",
        "description": "Retrieves paginated transactions with optional filters",
        "operationId": "GetTransactions",
        "parameters": [
          {
            "name": "limit",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 50
            },
            "description": "Number of transactions per page"
          },
          {
            "name": "offset",
            "in": "query",
            "schema": {
              "type": "integer",
              "default": 0
            },
            "description": "Pagination offset"
          },
          {
            "name": "start_date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Filter transactions after this date (YYYY-MM-DD)"
          },
          {
            "name": "end_date",
            "in": "query",
            "schema": {
              "type": "string",
              "format": "date"
            },
            "description": "Filter transactions before this date (YYYY-MM-DD)"
          },
          {
            "name": "category_id",
            "in": "query",
            "schema": {
              "type": "string"
            },
            "description": "Filter by Schedule C category"
          },
          {
            "name": "expense_type",
            "in": "query",
            "schema": {
              "type": "string",
              "enum": [
                "business",
                "personal",
                "mixed"
              ]
            },
            "description": "Filter by expense type"
          }
        ],
        "responses": {
          "200": {
            "description": "Transactions retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "transactions": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": {
                            "type": "string"
                          },
                          "amount": {
                            "type": "integer",
                            "description": "Amount in cents"
                          },
                          "currency": {
                            "type": "string"
                          },
                          "description": {
                            "type": "string"
                          },
                          "merchant_name": {
                            "type": "string"
                          },
                          "transacted_at": {
                            "type": "string",
                            "format": "date-time"
                          },
                          "schedule_c_category": {
                            "type": "string"
                          },
                          "expense_type": {
                            "type": "string"
                          },
                          "business_percentage": {
                            "type": "integer"
                          }
                        }
                      }
                    },
                    "total_count": {
                      "type": "integer"
                    },
                    "has_more": {
                      "type": "boolean"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Transactions"
        ]
      }
    },
    "/spend-management/transactions/{id}": {
      "get": {
        "summary": "Get Transaction",
        "description": "Retrieves a specific transaction by ID",
        "operationId": "GetTransaction",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Transaction ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Transaction retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Transaction not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Transactions"
        ]
      },
      "patch": {
        "summary": "Update Transaction",
        "description": "Updates transaction metadata (notes, tags)",
        "operationId": "UpdateTransaction",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Transaction ID"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "notes": {
                    "type": "string"
                  },
                  "tags": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transaction updated successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Transaction not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Transactions"
        ]
      }
    },
    "/spend-management/transactions/search": {
      "get": {
        "summary": "Search Transactions",
        "description": "Searches transactions by description, merchant name, or notes",
        "operationId": "SearchTransactions",
        "parameters": [
          {
            "name": "q",
            "in": "query",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Search query"
          }
        ],
        "responses": {
          "200": {
            "description": "Search results retrieved successfully"
          },
          "400": {
            "description": "Missing search query"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Transactions"
        ]
      }
    },
    "/spend-management/transactions/{id}/categorize": {
      "post": {
        "summary": "Categorize Transaction",
        "description": "Manually categorizes a transaction with IRS Schedule C categories",
        "operationId": "CategorizeTransaction",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Transaction ID"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "schedule_c_category",
                  "expense_type"
                ],
                "properties": {
                  "schedule_c_category": {
                    "type": "string",
                    "description": "IRS Schedule C category. Case-insensitive; surrounding whitespace is ignored.",
                    "enum": [
                      "LINE_8_ADVERTISING",
                      "LINE_9_CAR_AND_TRUCK_EXPENSES",
                      "LINE_10_COMMISSIONS_AND_FEES",
                      "LINE_11_CONTRACT_LABOR",
                      "LINE_12_DEPLETION",
                      "LINE_13_DEPRECIATION_SECTION_179",
                      "LINE_14_EMPLOYEE_BENEFIT_PROGRAMS",
                      "LINE_15_INSURANCE_OTHER_THAN_HEALTH",
                      "LINE_16A_MORTGAGE_INTEREST",
                      "LINE_16B_OTHER_INTEREST",
                      "LINE_17_LEGAL_AND_PROFESSIONAL_SERVICES",
                      "LINE_18_OFFICE_EXPENSE",
                      "LINE_19_PENSION_PROFIT_SHARING",
                      "LINE_20A_RENT_VEHICLES_EQUIPMENT",
                      "LINE_20B_RENT_BUSINESS_PROPERTY",
                      "LINE_21_REPAIRS_AND_MAINTENANCE",
                      "LINE_22_SUPPLIES",
                      "LINE_23_TAXES_AND_LICENSES",
                      "LINE_24A_TRAVEL",
                      "LINE_24B_DEDUCTIBLE_MEALS",
                      "LINE_25_UTILITIES",
                      "LINE_26_WAGES",
                      "LINE_27A_ENERGY_EFFICIENT_BUILDINGS",
                      "LINE_27B_OTHER_EXPENSES",
                      "LINE_30_HOME_OFFICE_DEDUCTION",
                      "NON_DEDUCTIBLE"
                    ],
                    "example": "LINE_27B_OTHER_EXPENSES"
                  },
                  "expense_type": {
                    "type": "string",
                    "enum": [
                      "business",
                      "personal",
                      "mixed",
                      "unclassified"
                    ],
                    "example": "business"
                  },
                  "business_percentage": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 100,
                    "description": "Business use percentage (0-100)",
                    "example": 100
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Transaction categorized successfully"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Transaction not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Transactions"
        ]
      }
    },
    "/spend-management/transactions/{id}/tax-details": {
      "patch": {
        "summary": "Update Tax Details",
        "description": "Updates tax classification and deductibility for a transaction",
        "operationId": "UpdateTaxDetails",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Transaction ID"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "schedule_c_category": {
                    "type": "string"
                  },
                  "business_percentage": {
                    "type": "integer"
                  },
                  "receipt_required": {
                    "type": "boolean"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Tax details updated successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Transaction not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Transactions"
        ]
      }
    },
    "/spend-management/transactions/{id}/receipt": {
      "post": {
        "summary": "Link Receipt",
        "description": "Links a receipt image to a transaction",
        "operationId": "LinkReceipt",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Transaction ID"
          }
        ],
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "receipt_url"
                ],
                "properties": {
                  "receipt_url": {
                    "type": "string",
                    "description": "URL to receipt image"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Receipt linked successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Transaction not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Transactions"
        ]
      }
    },
    "/spend-management/categorization/bulk": {
      "post": {
        "summary": "Bulk Categorize",
        "description": "Categorizes multiple transactions at once",
        "operationId": "BulkCategorize",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "transaction_ids",
                  "schedule_c_category",
                  "expense_type"
                ],
                "properties": {
                  "transaction_ids": {
                    "type": "array",
                    "items": {
                      "type": "string"
                    }
                  },
                  "schedule_c_category": {
                    "type": "string"
                  },
                  "expense_type": {
                    "type": "string",
                    "enum": [
                      "business",
                      "personal",
                      "mixed"
                    ]
                  },
                  "business_percentage": {
                    "type": "integer"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Bulk categorization completed successfully"
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Categorization"
        ]
      }
    },
    "/spend-management/tax/schedule-c": {
      "get": {
        "summary": "Get Schedule C Summary",
        "description": "Retrieves current year IRS Schedule C expense summary",
        "operationId": "GetScheduleCSummary",
        "responses": {
          "200": {
            "description": "Schedule C summary retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "year": {
                      "type": "integer"
                    },
                    "total_expenses": {
                      "type": "number"
                    },
                    "categories": {
                      "type": "object",
                      "description": "Breakdown by Schedule C category"
                    },
                    "unclassified_count": {
                      "type": "integer"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Tax & Reporting"
        ]
      }
    },
    "/spend-management/tax/schedule-c/{year}": {
      "get": {
        "summary": "Get Schedule C Summary By Year",
        "description": "Retrieves Schedule C summary for a specific year",
        "operationId": "GetScheduleCSummaryByYear",
        "parameters": [
          {
            "name": "year",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Tax year (e.g., 2026)"
          }
        ],
        "responses": {
          "200": {
            "description": "Schedule C summary retrieved successfully"
          },
          "400": {
            "description": "Invalid year"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Tax & Reporting"
        ]
      }
    },
    "/spend-management/tax/schedule-c/{year}/{month}": {
      "get": {
        "summary": "Get Schedule C Summary By Month",
        "description": "Retrieves Schedule C summary for a specific month",
        "operationId": "GetScheduleCSummaryByMonth",
        "parameters": [
          {
            "name": "year",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer"
            },
            "description": "Tax year"
          },
          {
            "name": "month",
            "in": "path",
            "required": true,
            "schema": {
              "type": "integer",
              "minimum": 1,
              "maximum": 12
            },
            "description": "Month (1-12)"
          }
        ],
        "responses": {
          "200": {
            "description": "Schedule C summary retrieved successfully"
          },
          "400": {
            "description": "Invalid year or month"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Tax & Reporting"
        ]
      }
    },
    "/spend-management/tax/unclassified": {
      "get": {
        "summary": "Get Unclassified Transactions",
        "description": "Retrieves transactions that haven't been categorized yet",
        "operationId": "GetUnclassifiedTransactions",
        "responses": {
          "200": {
            "description": "Unclassified transactions retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Tax & Reporting"
        ]
      }
    },
    "/spend-management/tax/export": {
      "post": {
        "summary": "Export Tax Report",
        "description": "Exports Schedule C report in CSV or PDF format",
        "operationId": "ExportTaxReport",
        "requestBody": {
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": [
                  "year",
                  "format"
                ],
                "properties": {
                  "year": {
                    "type": "integer"
                  },
                  "month": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 12,
                    "description": "Optional month filter"
                  },
                  "format": {
                    "type": "string",
                    "enum": [
                      "csv",
                      "pdf"
                    ]
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Report exported successfully",
            "content": {
              "text/csv": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              },
              "application/pdf": {
                "schema": {
                  "type": "string",
                  "format": "binary"
                }
              }
            }
          },
          "400": {
            "description": "Invalid request"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Tax & Reporting"
        ]
      }
    },
    "/spend-management/compliance/missing-receipts": {
      "get": {
        "summary": "Get Missing Receipts",
        "description": "Retrieves transactions that require receipts but don't have them",
        "operationId": "GetMissingReceipts",
        "responses": {
          "200": {
            "description": "Missing receipts retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Compliance"
        ]
      }
    },
    "/spend-management/compliance/status": {
      "get": {
        "summary": "Get Compliance Status",
        "description": "Retrieves overall tax compliance status and readiness",
        "operationId": "GetComplianceStatus",
        "responses": {
          "200": {
            "description": "Compliance status retrieved successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "compliance_score": {
                      "type": "integer",
                      "description": "Compliance score (0-100)"
                    },
                    "categorized_percentage": {
                      "type": "number"
                    },
                    "receipts_percentage": {
                      "type": "number"
                    },
                    "issues": {
                      "type": "array",
                      "items": {
                        "type": "string"
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Compliance"
        ]
      }
    },
    "/spend-management/notifications": {
      "get": {
        "summary": "Get Notifications",
        "description": "Retrieves spend management notifications (missing receipts, categorization reminders)",
        "operationId": "GetNotifications",
        "responses": {
          "200": {
            "description": "Notifications retrieved successfully"
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Notifications"
        ]
      }
    },
    "/spend-management/notifications/{id}/read": {
      "patch": {
        "summary": "Mark Notification Read",
        "description": "Marks a notification as read",
        "operationId": "MarkNotificationRead",
        "parameters": [
          {
            "name": "id",
            "in": "path",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Notification ID"
          }
        ],
        "responses": {
          "200": {
            "description": "Notification marked as read"
          },
          "401": {
            "description": "Unauthorized"
          },
          "404": {
            "description": "Notification not found"
          },
          "500": {
            "description": "Internal error"
          }
        },
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "tags": [
          "Spend Management - Notifications"
        ]
      }
    },
    "/spend-management/subscription/pricing": {
      "get": {
        "summary": "Get Subscription Pricing",
        "description": "Returns all active plan prices fetched live from Stripe, cached for 1 hour. No authentication required — safe to call from public pricing pages.\n\nReturns 4 price options: Lite monthly, Lite yearly, Premium monthly, Premium yearly. Use the `price_id` from this response as the body for `POST /subscription/checkout`.\n\nRequires `STRIPE_LITE_PRODUCT_ID` and `STRIPE_PREMIUM_PRODUCT_ID` env vars to be set on the server.",
        "operationId": "GetSubscriptionPricing",
        "tags": [
          "Spend Management - Subscriptions"
        ],
        "responses": {
          "200": {
            "description": "Available pricing plans",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "plans": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "plan": {
                            "type": "string",
                            "enum": ["lite", "premium"],
                            "example": "premium"
                          },
                          "interval": {
                            "type": "string",
                            "enum": ["month", "year"],
                            "example": "month"
                          },
                          "price_id": {
                            "type": "string",
                            "description": "Stripe Price ID — pass this to POST /subscription/checkout",
                            "example": "price_1UUGZpG2wqxh9c5abGi5vgTz"
                          },
                          "product_id": {
                            "type": "string",
                            "example": "prod_xxx"
                          },
                          "amount": {
                            "type": "integer",
                            "description": "Price in smallest currency unit (cents for USD)",
                            "example": 999
                          },
                          "currency": {
                            "type": "string",
                            "example": "usd"
                          },
                          "display_amount": {
                            "type": "string",
                            "description": "Human-readable price string",
                            "example": "$9.99/month"
                          },
                          "features": {
                            "type": "array",
                            "description": "Entitlement lookup keys included in this plan",
                            "items": { "type": "string" },
                            "example": ["basic_analytics", "transaction_history", "budget_management", "ai_insights", "schedule_c_reports", "multiple_bank_accounts", "export_reports"]
                          }
                        }
                      },
                      "example": [
                        { "plan": "lite", "interval": "month", "price_id": "price_xxx", "amount": 999, "currency": "usd", "display_amount": "$9.99/month", "features": ["basic_analytics", "transaction_history", "budget_management"] },
                        { "plan": "lite", "interval": "year", "price_id": "price_xxx", "amount": 9999, "currency": "usd", "display_amount": "$99.99/year", "features": ["basic_analytics", "transaction_history", "budget_management"] },
                        { "plan": "premium", "interval": "month", "price_id": "price_xxx", "amount": 1999, "currency": "usd", "display_amount": "$19.99/month", "features": ["basic_analytics", "transaction_history", "budget_management", "ai_insights", "schedule_c_reports", "multiple_bank_accounts", "export_reports"] },
                        { "plan": "premium", "interval": "year", "price_id": "price_xxx", "amount": 19999, "currency": "usd", "display_amount": "$199.99/year", "features": ["basic_analytics", "transaction_history", "budget_management", "ai_insights", "schedule_c_reports", "multiple_bank_accounts", "export_reports"] }
                      ]
                    }
                  }
                }
              }
            }
          },
          "500": {
            "description": "Internal error (Stripe unreachable or product IDs not configured)"
          }
        }
      }
    },
    "/spend-management/subscription/checkout": {
      "post": {
        "summary": "Create Subscription Checkout Session",
        "description": "Creates a Stripe Checkout session for the given price ID. Redirects the user to Stripe-hosted checkout to complete payment. Returns a Stripe Checkout URL.\n\nReturns 409 if the user already has an active subscription — use the portal endpoint to change plans.",
        "operationId": "CreateCheckoutSession",
        "tags": [
          "Spend Management - Subscriptions"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["price_id"],
                "properties": {
                  "price_id": {
                    "type": "string",
                    "description": "Stripe Price ID for the plan to subscribe to.",
                    "example": "price_1Abc123"
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": {
            "description": "Checkout session created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "description": "Stripe Checkout URL to redirect the user to.",
                      "example": "https://checkout.stripe.com/pay/cs_test_xxx"
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "price_id missing or invalid"
          },
          "401": {
            "description": "Unauthorized"
          },
          "409": {
            "description": "User already has an active subscription"
          },
          "500": {
            "description": "Internal error"
          }
        }
      }
    },
    "/spend-management/subscription/portal": {
      "post": {
        "summary": "Create Billing Portal Session",
        "description": "Creates a Stripe Billing Portal session so the user can manage, upgrade, downgrade, or cancel their existing subscription. Returns a URL to redirect the user to.",
        "operationId": "CreatePortalSession",
        "tags": [
          "Spend Management - Subscriptions"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Portal session created",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "description": "Stripe Billing Portal URL to redirect the user to.",
                      "example": "https://billing.stripe.com/session/xxx"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        }
      }
    },
    "/spend-management/subscription": {
      "get": {
        "summary": "Get Current Subscription",
        "description": "Returns the current subscription for the authenticated user. If the user is on the free plan (no paid subscription), returns `{ \"plan\": \"free\", \"status\": \"none\", \"subscription\": null }`.",
        "operationId": "GetSubscription",
        "tags": [
          "Spend Management - Subscriptions"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Current subscription",
            "content": {
              "application/json": {
                "schema": {
                  "oneOf": [
                    {
                      "type": "object",
                      "description": "Free plan (no paid subscription)",
                      "properties": {
                        "plan": { "type": "string", "example": "free" },
                        "status": { "type": "string", "example": "none" },
                        "subscription": { "type": "object", "nullable": true, "example": null }
                      }
                    },
                    {
                      "type": "object",
                      "description": "Active paid subscription",
                      "properties": {
                        "subscription": {
                          "type": "object",
                          "properties": {
                            "id": { "type": "string" },
                            "user_id": { "type": "string" },
                            "stripe_customer_id": { "type": "string" },
                            "stripe_subscription_id": { "type": "string" },
                            "stripe_price_id": { "type": "string" },
                            "stripe_product_id": { "type": "string" },
                            "plan": {
                              "type": "string",
                              "enum": ["free", "lite", "premium"],
                              "example": "premium"
                            },
                            "status": {
                              "type": "string",
                              "enum": ["active", "canceled", "incomplete", "incomplete_expired", "past_due", "trialing", "unpaid", "paused"],
                              "example": "active"
                            },
                            "current_period_start": { "type": "string", "format": "date-time" },
                            "current_period_end": { "type": "string", "format": "date-time" },
                            "cancel_at_period_end": { "type": "boolean" },
                            "canceled_at": { "type": "string", "format": "date-time", "nullable": true },
                            "trial_start": { "type": "string", "format": "date-time", "nullable": true },
                            "trial_end": { "type": "string", "format": "date-time", "nullable": true },
                            "created_at": { "type": "string", "format": "date-time" },
                            "updated_at": { "type": "string", "format": "date-time" }
                          }
                        }
                      }
                    }
                  ]
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        }
      }
    },
    "/spend-management/subscription/entitlements": {
      "get": {
        "summary": "Get Feature Entitlements",
        "description": "Returns all feature entitlement rows for the authenticated user. Each entitlement has a `lookup_key` and an `is_active` flag. Free plan users have no active entitlements.\n\n**Entitlement keys by plan:**\n- **Lite**: `basic_analytics`, `transaction_history`, `budget_management`\n- **Premium**: all Lite keys + `ai_insights`, `schedule_c_reports`, `multiple_bank_accounts`, `export_reports`",
        "operationId": "GetEntitlements",
        "tags": [
          "Spend Management - Subscriptions"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "User entitlements",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "entitlements": {
                      "type": "array",
                      "items": {
                        "type": "object",
                        "properties": {
                          "id": { "type": "string" },
                          "user_id": { "type": "string" },
                          "lookup_key": {
                            "type": "string",
                            "enum": [
                              "basic_analytics",
                              "transaction_history",
                              "budget_management",
                              "ai_insights",
                              "schedule_c_reports",
                              "multiple_bank_accounts",
                              "export_reports"
                            ],
                            "example": "ai_insights"
                          },
                          "is_active": { "type": "boolean", "example": true },
                          "updated_at": { "type": "string", "format": "date-time" }
                        }
                      }
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "500": {
            "description": "Internal error"
          }
        }
      }
    },
    "/spend-management/admin/backfill-embeddings": {
      "post": {
        "summary": "Start Transaction Embedding Backfill (Admin)",
        "description": "Starts an async background job that generates and stores vector embeddings for all transactions that currently have none. Returns 202 immediately — poll `GET /spend-management/admin/backfill-embeddings/status` to track progress.\n\nNew transactions are embedded automatically on insert; this endpoint only needs to be called once for pre-existing rows. Returns 409 if a backfill is already running.",
        "operationId": "BackfillTransactionEmbeddings",
        "tags": [
          "Spend Management - Admin"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "requestBody": {
          "required": false,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "properties": {
                  "batch_size": {
                    "type": "integer",
                    "description": "Maximum number of transactions to embed in this run. 0 or omitted means all rows with no embedding.",
                    "example": 500,
                    "default": 0
                  }
                }
              }
            }
          }
        },
        "responses": {
          "202": {
            "description": "Backfill started in background",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "message": {
                      "type": "string",
                      "example": "Backfill started in background"
                    },
                    "status_url": {
                      "type": "string",
                      "example": "/spend-management/admin/backfill-embeddings/status"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          },
          "409": {
            "description": "A backfill is already running"
          },
          "500": {
            "description": "Internal error"
          }
        }
      },
      "get": {
        "summary": "Get Embedding Backfill Status (Admin)",
        "description": "Returns the current state of the transaction embedding backfill job. `status` will be `not_started`, `running`, `done`, or `error`.",
        "operationId": "BackfillTransactionEmbeddingsStatus",
        "tags": [
          "Spend Management - Admin"
        ],
        "security": [
          {
            "BearerAuth": []
          }
        ],
        "responses": {
          "200": {
            "description": "Backfill job status",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "status": {
                      "type": "string",
                      "enum": ["not_started", "running", "done", "error"],
                      "example": "done"
                    },
                    "embedded": {
                      "type": "integer",
                      "description": "Transactions successfully embedded so far",
                      "example": 342
                    },
                    "started_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "finished_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "error": {
                      "type": "string",
                      "description": "Error message if status is error"
                    }
                  }
                }
              }
            }
          },
          "401": {
            "description": "Unauthorized"
          }
        }
      }
    },
    "/webhooks/stripe/spend-management": {
      "post": {
        "summary": "Stripe Spend Management Webhook",
        "description": "Receives Stripe webhook events for both Financial Connections and Subscriptions. Authentication via Stripe signature verification.\n\n**Financial Connections events:** `financial_connections.account.created`, `financial_connections.account.disconnected`, `financial_connections.account.refreshed.balance`, `financial_connections.account.refreshed.transactions`\n\n**Subscription events:** `checkout.session.completed`, `customer.subscription.created`, `customer.subscription.updated`, `customer.subscription.deleted`, `invoice.payment_succeeded`, `invoice.payment_failed`",
        "operationId": "HandleStripeSpendManagementWebhook",
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "description": "Stripe webhook event payload"
              }
            }
          }
        },
        "parameters": [
          {
            "name": "Stripe-Signature",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string"
            },
            "description": "Stripe webhook signature for verification"
          }
        ],
        "responses": {
          "200": {
            "description": "Webhook processed successfully",
            "content": {
              "application/json": {
                "schema": {
                  "type": "object",
                  "properties": {
                    "received": {
                      "type": "boolean",
                      "example": true
                    }
                  }
                }
              }
            }
          },
          "400": {
            "description": "Invalid request or signature verification failed"
          },
          "500": {
            "description": "Internal error processing webhook"
          }
        },
        "tags": [
          "Spend Management - Webhooks"
        ]
      }
    }
  },
  "components": {
    "securitySchemes": {
      "ApiKeyAuth": {
        "type": "apiKey",
        "in": "header",
        "name": "X-API-Key",
        "description": "API key for authentication. Format: bkv_test_your_api_key or bkv_live_your_api_key"
      },
      "BearerAuth": {
        "type": "http",
        "scheme": "bearer",
        "bearerFormat": "JWT",
        "description": "JWT token from authentication endpoints"
      }
    },
    "schemas": {
      "ErrorResponse": {
        "type": "object",
        "properties": {
          "error": {
            "type": "object",
            "properties": {
              "code": {
                "type": "string"
              },
              "message": {
                "type": "string"
              },
              "details": {
                "type": "string"
              }
            }
          },
          "request_id": {
            "type": "string"
          }
        }
      },
      "AddVehicleRequest": {
        "type": "object",
        "properties": {
          "license_plate": {
            "type": "string",
            "description": "License plate number (Flow 1: with state_code)",
            "example": "PMX4951"
          },
          "state_code": {
            "type": "string",
            "description": "State code for license plate (Flow 1)",
            "example": "GA"
          },
          "vin": {
            "type": "string",
            "description": "Vehicle Identification Number (Flow 2: direct entry)",
            "example": "1HGBH41JXMN109186"
          },
          "nickname": {
            "type": "string",
            "description": "Optional nickname for the vehicle"
          },
          "is_default": {
            "type": "boolean",
            "description": "Whether this is the default vehicle",
            "default": false
          },
          "metadata": {
            "type": "object",
            "description": "Optional metadata"
          }
        },
        "description": "Provide either (license_plate + state_code) OR (vin)"
      },
      "AddVehicleResponse": {
        "type": "object",
        "properties": {
          "success": {
            "type": "boolean"
          },
          "vehicle": {
            "type": "object",
            "properties": {
              "vin": {
                "type": "string"
              },
              "make": {
                "type": "string"
              },
              "model": {
                "type": "string"
              },
              "model_year": {
                "type": "integer"
              },
              "trim": {
                "type": "string"
              },
              "body_class": {
                "type": "string"
              },
              "vehicle_type": {
                "type": "string"
              },
              "fuel_type_primary": {
                "type": "string"
              },
              "engine_model": {
                "type": "string"
              },
              "engine_cylinders": {
                "type": "integer"
              },
              "engine_hp": {
                "type": "integer"
              },
              "nickname": {
                "type": "string"
              },
              "is_default": {
                "type": "boolean"
              }
            }
          },
          "lookup_method": {
            "type": "string",
            "enum": [
              "license_plate",
              "direct_vin"
            ]
          },
          "oneauto_data": {
            "type": "object",
            "description": "Enriched data from OneAuto API (if license plate lookup)"
          },
          "db": {
            "type": "object",
            "description": "Full database record"
          }
        }
      },
      "ConnectionType": {
        "type": "object",
        "properties": {
          "type_key": {
            "type": "string",
            "description": "Unique key for the connection type",
            "example": "bank"
          },
          "category": {
            "type": "string",
            "description": "Category of the connection",
            "enum": ["banking", "accounting", "rideshare", "email"]
          },
          "display_name": {
            "type": "string",
            "description": "Human-readable name",
            "example": "Bank Account"
          },
          "description": {
            "type": "string",
            "description": "Description of the connection type"
          },
          "provider": {
            "type": "string",
            "description": "Provider name",
            "example": "Stripe Financial Connections"
          },
          "icon_url": {
            "type": "string",
            "format": "uri",
            "description": "Icon URL for the connection type"
          },
          "supports_sync": {
            "type": "boolean",
            "description": "Whether the connection supports data syncing"
          },
          "supports_webhooks": {
            "type": "boolean",
            "description": "Whether the connection supports webhooks"
          },
          "supports_expense_import": {
            "type": "boolean",
            "description": "Whether the connection supports expense importing"
          },
          "auth_type": {
            "type": "string",
            "description": "Authentication type",
            "enum": ["oauth2", "stripe_fc", "api_key", "email_forwarding"]
          },
          "setup_instructions": {
            "type": "string",
            "description": "Setup instructions for the user"
          }
        }
      },
      "Connection": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string",
            "format": "uuid",
            "description": "Connection ID"
          },
          "user_id": {
            "type": "string",
            "format": "uuid",
            "description": "User ID"
          },
          "type_key": {
            "type": "string",
            "description": "Connection type key"
          },
          "display_name": {
            "type": "string",
            "description": "User-defined display name"
          },
          "external_id": {
            "type": "string",
            "description": "External provider's connection ID"
          },
          "status": {
            "type": "string",
            "enum": ["pending_auth", "active", "error", "disconnected", "expired"],
            "description": "Connection status"
          },
          "last_synced_at": {
            "type": "string",
            "format": "date-time",
            "description": "Last successful sync timestamp"
          },
          "next_sync_at": {
            "type": "string",
            "format": "date-time",
            "description": "Next scheduled sync timestamp"
          },
          "error_message": {
            "type": "string",
            "description": "Last error message if status is error"
          },
          "metadata": {
            "type": "object",
            "description": "Additional connection-specific metadata"
          },
          "is_active": {
            "type": "boolean",
            "description": "Whether the connection is active"
          },
          "created_at": {
            "type": "string",
            "format": "date-time"
          },
          "updated_at": {
            "type": "string",
            "format": "date-time"
          }
        }
      },
      "ConnectionWithType": {
        "allOf": [
          {
            "$ref": "#/components/schemas/Connection"
          },
          {
            "type": "object",
            "properties": {
              "type_display_name": {
                "type": "string",
                "description": "Display name of the connection type"
              },
              "provider_name": {
                "type": "string",
                "description": "Provider name"
              },
              "icon_url": {
                "type": "string",
                "format": "uri",
                "description": "Icon URL"
              },
              "supports_sync": {
                "type": "boolean"
              },
              "supports_webhooks": {
                "type": "boolean"
              },
              "supports_expense_import": {
                "type": "boolean"
              }
            }
          }
        ]
      },
      "ConnectionDetailResponse": {
        "allOf": [
          {
            "$ref": "#/components/schemas/ConnectionWithType"
          },
          {
            "type": "object",
            "properties": {
              "sync_history": {
                "type": "array",
                "description": "Recent sync history",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string",
                      "format": "uuid"
                    },
                    "sync_type": {
                      "type": "string",
                      "enum": ["balance", "transactions", "expenses", "full"]
                    },
                    "status": {
                      "type": "string",
                      "enum": ["succeeded", "failed", "in_progress"]
                    },
                    "records_synced": {
                      "type": "integer"
                    },
                    "error_message": {
                      "type": "string"
                    },
                    "started_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "completed_at": {
                      "type": "string",
                      "format": "date-time"
                    },
                    "duration_ms": {
                      "type": "integer"
                    }
                  }
                }
              },
              "recent_expenses": {
                "type": "array",
                "description": "Recent expenses from this connection",
                "items": {
                  "type": "object",
                  "properties": {
                    "id": {
                      "type": "string"
                    },
                    "amount": {
                      "type": "number"
                    },
                    "currency": {
                      "type": "string"
                    },
                    "description": {
                      "type": "string"
                    },
                    "date": {
                      "type": "string",
                      "format": "date-time"
                    }
                  }
                }
              },
              "expenses_summary": {
                "type": "object",
                "properties": {
                  "total_count": {
                    "type": "integer"
                  },
                  "total_amount": {
                    "type": "number"
                  },
                  "deductible_amount": {
                    "type": "number"
                  },
                  "currency": {
                    "type": "string"
                  }
                }
              }
            }
          }
        ]
      }
    }
  },
  "tags": [
    {
      "name": "Spend Management - Bank Accounts",
      "description": "Manage bank account connections via Stripe Financial Connections"
    },
    {
      "name": "Spend Management - Connections",
      "description": "Unified API for managing connections to banks, accounting software, rideshare, and email platforms"
    },
    {
      "name": "Spend Management - Balances",
      "description": "View account balances and total cash flow"
    },
    {
      "name": "Spend Management - Transactions",
      "description": "View, search, and manage bank transactions"
    },
    {
      "name": "Spend Management - Categorization",
      "description": "AI-powered IRS Schedule C expense categorization"
    },
    {
      "name": "Spend Management - Tax & Reporting",
      "description": "Schedule C summaries and tax report exports"
    },
    {
      "name": "Spend Management - Compliance",
      "description": "Tax compliance status and receipt tracking"
    },
    {
      "name": "Spend Management - Notifications",
      "description": "Spend management alerts and reminders"
    },
    {
      "name": "Spend Management - Webhooks",
      "description": "Stripe Financial Connections webhook endpoints"
    }
  ]
}