openapi: 3.1.0
info:
  title: Health Metrics API
  description: API for analyzing images to extract health metrics from medical devices
  version: 1.0.0
  contact:
    name: Health Metrics Team

servers:
  - url: snap-health-microservice.deno.dev
    description: Remote deno server

tags:
  - name: health
    description: API health check
  - name: analyze
    description: Image analysis and health metrics extraction
  - name: documentation
    description: API documentation

paths:
  /health:
    get:
      summary: Health check endpoint
      description: Verify that the API is running
      tags:
        - health
      responses:
        '200':
          description: API is healthy
          content:
            application/json:
              schema:
                type: object
                properties:
                  status:
                    type: string
                    example: "ok"

  /api-docs:
    get:
      summary: API documentation
      description: Get documentation about API endpoints
      tags:
        - documentation
      responses:
        '200':
          description: Documentation response
          content:
            application/json:
              schema:
                type: object
                properties:
                  service:
                    type: string
                  version:
                    type: string
                  endpoints:
                    type: object

  /api/v1/analyze:
    post:
      summary: Analyze image for health metrics
      description: Upload an image of a health device (like blood pressure monitor, glucose meter, scale) to extract health metrics
      tags:
        - analyze
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ImageUploadRequest'
      responses:
        '200':
          description: Successful analysis
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExtractedHealthMetrics'
              example:
                metrics:
                  - metricType: "bloodPressureSystolic"
                    value: 120
                    unit: "mmHg"
                    confidence: 0.95
                    label: "Systolic Blood Pressure"
                  - metricType: "bloodPressureDiastolic"
                    value: 80
                    unit: "mmHg"
                    confidence: 0.95
                    label: "Diastolic Blood Pressure"
        '400':
          description: Invalid request
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  details:
                    type: object
              example:
                error: "Invalid request"
                details:
                  image:
                    _errors: ["Image data is required"]
        '500':
          description: Server error
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              example:
                error: "Failed to process image"

  /:
    get:
      summary: Home page
      description: Get the UI home page
      responses:
        '200':
          description: HTML content for the home page
          content:
            text/html:
              schema:
                type: string

components:
  schemas:
    ImageUploadRequest:
      type: object
      required:
        - image
      properties:
        image:
          type: string
          description: Base64 encoded image data
          example: "data:image/jpeg;base64,/9j/4AAQSkZJRgABA..."
        imageFormat:
          type: string
          enum: [jpeg, png, webp]
          default: jpeg
          description: Format of the uploaded image
        includeTimestamp:
          type: boolean
          default: false
          description: Include timestamp in the metrics output
        model:
          type: string
          description: Optional AI model name to use for extraction
          example: "google/gemini-2.0-flash-001"
    
    ExtractedHealthMetric:
      type: object
      required:
        - metricType
        - value
        - unit
        - confidence
      properties:
        metricType:
          type: string
          description: Type of health metric
          example: "bloodPressureSystolic"
        value:
          type: number
          description: Numerical value of the measurement
          example: 120
        unit:
          type: string
          description: Unit of measurement
          example: "mmHg"
        confidence:
          type: number
          format: float
          minimum: 0
          maximum: 1
          description: Confidence score between 0 and 1, where 1 is highest confidence
          example: 0.95
        label:
          type: string
          description: Human-readable label for the metric
          example: "Systolic Blood Pressure"
        timestamp:
          type: string
          format: date-time
          description: ISO 8601 formatted timestamp when measurement was taken
          example: "2023-03-15T08:30:00Z"
    
    ExtractedHealthMetrics:
      type: object
      required:
        - metrics
      properties:
        metrics:
          type: array
          description: Array of health metrics found in the image
          items:
            $ref: '#/components/schemas/ExtractedHealthMetric'