openapi: 3.1.0
info:
  title: Tango Lookups Inbound API
  version: "0.8"
  description: |
    Async REST API: client PUTs custom-lookup dropdown values into Tango.
    The combination `(lookup_name, lookup_code)` is the upsert key; for
    multi-country clients, `country` is added to the key. Two-call pattern
    with `gu_id` polling.

    Only the following custom lookups are supported by this integration:
    `CLOV_COST_CENTER`, `CLOV_INTERNAL_ORDER`, `CLOV_PRODUCT_LIST`,
    `CLOV_PROFIT_CENTER`.
  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: Lookups
  - name: Status
paths:
  /v1/common/batch/external-lookups:
    put:
      summary: Submit custom lookup values (async)
      operationId: putExternalLookupsBatch
      tags: [Lookups]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/LookupBatchRequest"
            examples:
              default:
                value:
                  records:
                    - lookup_name: "CLOV_PROFIT_CENTER"
                      lookup_code: "670893"
                      lookup_value: "670893"
                      lookup_desc: "670893"
                      status: "ACTIVE"
                      country: "USA"
                      sequence: "10"
                      ext_attr1: "GD"
                      ext_attr2: "001"
      responses:
        "200":
          description: Accepted for async processing.
          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:
    LookupBatchRequest:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/LookupRecord"
    LookupRecord:
      type: object
      required:
        - lookup_name
        - lookup_code
        - lookup_value
        - status
        - sequence
      properties:
        lookup_name:
          type: string
          description: |
            Lookup type. Allowed: `CLOV_COST_CENTER`, `CLOV_INTERNAL_ORDER`,
            `CLOV_PRODUCT_LIST`, `CLOV_PROFIT_CENTER`.
        lookup_code:
          type: string
          description: Per-value code. With `lookup_name` (and `country` if multi-country) forms the upsert key.
        lookup_value: { type: string, description: "Display value." }
        lookup_desc: { type: string, description: "Description." }
        status:
          type: string
          description: "`ACTIVE` displays the lookup in UI; any other value hides it."
        country:
          type: string
          description: "ISO 3-letter country code. Required for multi-country clients."
        sequence:
          type: number
          description: "Display order in UI. Whole numbers only."
        ext_attr1:  { type: string }
        ext_attr2:  { type: string }
        ext_attr3:  { type: string }
        ext_attr4:  { type: string }
        ext_attr5:  { type: string }
        ext_attr6:  { type: string }
        ext_attr7:  { type: string }
        ext_attr8:  { type: string }
        ext_attr9:  { type: string }
        ext_attr10: { type: string }
        ext_attr11: { type: string }
        ext_attr12: { type: string }
        ext_attr13: { type: string }
        ext_attr14: { type: string }
        ext_attr15: { type: string }
        ext_attr16: { type: string }
    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: { type: string }
                  lookup_code: { type: string }
                  error: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
