openapi: 3.1.0
info:
  title: Tango MAC Comment Inbound API
  version: "0.8"
  description: |
    Async REST API: client PUTs comments (Internal or External Notes) onto
    MAC requests in Tango. Creates new comments; updates existing comments
    when `tango_comment_id` is supplied. Does NOT delete.
  x-direction: inbound
  x-source: Client System
  x-destination: Tango
servers:
  - url: https://api.tangoanalytics.com
    description: Production
  - url: https://testapi.tangoanalytics.com
    description: Test (SIT/UAT)
tags: [{name: MAC Comments}, {name: Status}]
paths:
  /v1/common/batch/comments:
    put:
      summary: Submit MAC comments (async)
      operationId: putMacComments
      tags: [MAC Comments]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/MacCommentBatch"
      responses:
        "200":
          description: Accepted.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AcceptedResponse"
  /v1/batch/status:
    get:
      summary: Poll processing status by gu_id
      operationId: getBatchStatus
      tags: [Status]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: gu_id
          required: true
          schema: { type: string, format: uuid }
      responses:
        "200":
          description: Status payload.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/StatusResponse"
components:
  securitySchemes:
    xClientHeader: { type: apiKey, in: header, name: x-client }
    xApiKeyHeader: { type: apiKey, in: header, name: x-api-key }
  parameters:
    XClient: { name: x-client, in: header, required: true, schema: { type: string } }
    XApiKey: { name: x-api-key, in: header, required: true, schema: { type: string } }
  schemas:
    MacCommentBatch:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/MacComment"
    MacComment:
      type: object
      description: |
        At least one of `entity_number` (MAC Number) or `ext_entity_number`
        (Client Integration ID) must be present to identify the MAC request.
      required:
        - ext_entity_number
        - comments
        - entity_type
      properties:
        entity_number: { type: string, description: "MAC Number; one of entity_number/ext_entity_number required." }
        ext_entity_number: { type: string, description: "Client Integration ID." }
        tango_comment_id: { type: number, description: "Provide to update an existing comment." }
        comments_category: { type: string, description: 'Sample: "Notes".' }
        comment_type: { type: string, description: "Lookup." }
        subject: { type: string }
        comments: { type: string }
        entity_type:
          type: string
          enum: [MACINTERNAL, MACEXTERNAL]
          description: |
            Source describes as "Can either be MAC Internal or MAC External".
            Sample data shows `MACEXTERNAL`. Both single-word forms are used here.
    AcceptedResponse:
      type: object
      required: [status, gu_id]
      properties:
        status: { type: string, enum: [OK, Error] }
        status_message: { type: string }
        gu_id: { type: string, format: uuid }
    StatusResponse:
      oneOf:
        - { type: object, properties: { status: { type: string, const: PROCESSING } } }
        - type: object
          required: [status, total_records]
          properties:
            status: { type: string, const: COMPLETED }
            total_records: { type: integer }
            errors: { type: 'null' }
        - type: object
          required: [status, total_records, errors]
          properties:
            status: { type: string, const: ERROR }
            total_records: { type: integer }
            errors:
              type: array
              items:
                type: object
                required: [record_index, error]
                properties:
                  record_index: { type: integer }
                  record_key:
                    oneOf:
                      - { type: string }
                      - { type: integer }
                  error: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
