openapi: 3.1.0
info:
  title: Tango Update Store Contacts API
  version: "0.5"
  description: |
    Async REST API: client PUTs store-contact records to Tango. Upsert key
    is `(store_number, role)`. A store record must already exist in Tango;
    contacts for non-existent stores fail. Two-call pattern with `gu_id`
    polling.
  x-direction: inbound
  x-source: Client System
  x-destination: Tango
servers:
  - url: https://api.tangoanalytics.com
    description: Production (host TBD per source — placeholder)
  - url: https://testapi.tangoanalytics.com
    description: Test (host TBD per source — placeholder)
tags:
  - name: Store Contacts
  - name: Status
paths:
  /v1/locationmgmt/locationcontacts:
    put:
      summary: Insert/update store contact records (async)
      operationId: putStoreContactsBatch
      tags: [Store Contacts]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/StoreContactBatchRequest"
            examples:
              default:
                value:
                  records:
                    - store_number: "98722-01"
                      role: "RE_MANAGER"
                      first_name: "John"
                      last_name: "Markson"
                      company: "WC Franchisee"
                      business_phone: "1234567890"
                      extension: "241"
                      email: "john_markson@wc.com"
                      fax: "3546128323"
                      status: "A"
      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:
    StoreContactBatchRequest:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/StoreContactRecord"
    StoreContactRecord:
      type: object
      required:
        - store_number
        - role
        - first_name
        - last_name
        - company
        - email
      properties:
        store_number:
          type: string
          description: Must reference an existing store in Tango. With `role` forms the upsert key.
        role:
          type: string
          description: |
            Must match a `CONTACTS_ROLE` lookup code. With `store_number`
            forms the upsert key (the same role cannot exist twice on
            a store).
        first_name: { type: string }
        last_name: { type: string }
        company: { type: string }
        business_phone: { type: string }
        extension: { type: string }
        email: { type: string, format: email }
        fax: { type: string }
        status:
          type: string
          enum: [A, R]
          description: "Expected `A` (Active) or `R` (Removed)."
    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 }
                  error: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
