openapi: 3.1.0
info:
  title: SYNO API
  description: >
    AI-powered analysis of anonymized therapy session notes.
    Returns key themes, reflection questions, supervision reports, and pattern analytics.
  version: 1.0.0
  contact:
    email: bandina.larisa@yandex.ru
    url: https://getsyno.ru
  license:
    name: Proprietary

servers:
  - url: https://lhofxraofzyocsotozwb.supabase.co/functions/v1/api-gateway
    description: Production API

security:
  - bearerAuth: []

paths:
  /analyze:
    post:
      operationId: analyzeSession
      summary: Analyze anonymized therapy session notes
      description: >
        Submit anonymized session text and receive structured analysis including
        key themes, session dynamics, reflection questions, supervision report, and patterns.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AnalyzeRequest'
      responses:
        '200':
          description: Successful analysis
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnalyzeResponse'
        '400':
          description: Invalid request (text too short or missing)
        '401':
          description: Invalid or missing API key
        '502':
          description: AI analysis failed

  /analyses:
    get:
      operationId: listAnalyses
      summary: List saved analyses
      parameters:
        - name: limit
          in: query
          schema:
            type: integer
            default: 20
            maximum: 100
        - name: offset
          in: query
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Paginated list of analyses
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AnalysesListResponse'
        '401':
          description: Invalid or missing API key

  /analyses/{id}:
    get:
      operationId: getAnalysis
      summary: Get a specific analysis by ID
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
            format: uuid
      responses:
        '200':
          description: Full analysis object
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Analysis'
        '401':
          description: Invalid or missing API key
        '404':
          description: Analysis not found

components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: API key issued at https://getsyno.ru (prefix syno_)

  schemas:
    AnalyzeRequest:
      type: object
      required: [text]
      properties:
        text:
          type: string
          minLength: 20
          description: Anonymized session notes (names/dates/places replaced with [NAME]/[DATE]/[PLACE])
        session_label:
          type: string
          description: Optional label, e.g. "Client 3, session 12"

    AnalyzeResponse:
      type: object
      properties:
        id:
          type: string
          format: uuid
        created_at:
          type: string
          format: date-time
        session_label:
          type: string
          nullable: true
        analysis:
          $ref: '#/components/schemas/AnalysisResult'

    Analysis:
      type: object
      properties:
        id:
          type: string
          format: uuid
        created_at:
          type: string
          format: date-time
        session_label:
          type: string
          nullable: true
        analysis_result:
          $ref: '#/components/schemas/AnalysisResult'

    AnalysisResult:
      type: object
      properties:
        key_themes:
          type: array
          items:
            type: object
            properties:
              theme:
                type: string
              description:
                type: string
              evidence:
                type: string
        session_dynamics:
          type: object
          properties:
            client_state:
              type: string
            therapist_interventions:
              type: string
            interaction_pattern:
              type: string
        reflection_questions:
          type: array
          items:
            type: string
        supervision_report:
          type: object
          properties:
            summary:
              type: string
            challenges:
              type: string
            discussion_questions:
              type: array
              items:
                type: string
            hypotheses:
              type: string
        patterns:
          type: object
          properties:
            recurring_themes:
              type: array
              items:
                type: string
            potential_transference:
              type: string
            resistance_indicators:
              type: string

    AnalysesListResponse:
      type: object
      properties:
        data:
          type: array
          items:
            $ref: '#/components/schemas/Analysis'
        total:
          type: integer
        limit:
          type: integer
        offset:
          type: integer
