openapi: 3.1.0
info:
  title: Tango Space HR Inbound API
  version: "1.8"
  description: |
    Async REST API: client PUTs Person/HR records to Tango. Tango creates
    or updates People records under Space Management. Upsert key:
    `person_number`. Two-call pattern with `gu_id`.

    The status-API response includes both `processed_records` and
    `error_records` counts in addition to `total_records`. If there are no
    errors, `error_records` is omitted; if there are no processed records,
    `processed_records` is omitted.

    `total_office_days` is **calculated** by Tango as the sum of the seven
    daily flags (`office_on_sun..sat`) regardless of any value sent in the
    JSON.
  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: People (HR)}, {name: Status}]
paths:
  /v1/spacemgmt/batch/people:
    put:
      summary: Submit Person/HR records (async)
      operationId: putPeopleBatch
      tags: [People (HR)]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/PeopleBatchRequest"
      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:
    PeopleBatchRequest:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/PersonRecord"
    PersonRecord:
      type: object
      required:
        - person_number
        - first_name
        - last_name
        - status
        - country
      properties:
        person_number: { type: string, description: "Employee Number; upsert key." }
        first_name: { type: string }
        middle_name: { type: string }
        last_name: { type: string }
        other_name: { type: string }
        employee_type: { type: string, description: "Lookup." }
        cost_center:
          type: string
          description: |
            Business Unit Code. NOT mandatory for the integration, BUT once an
            employee is assigned to a department in Tango, the cost_center
            cannot be updated to NULL through the integration.
        title: { type: string, description: 'Client Label "Position".' }
        building_assigned: { type: string, description: "Must reference an existing building in Tango." }
        manager_number: { type: string, description: "Valid person_number of manager." }
        shift_worker:
          type: string
          enum: [Y, N]
          description: 'Client Label "People Manager" — note the label/field semantic mismatch.'
        status:
          type: string
          enum: [Active, Inactive]
        country: { type: string, description: "ISO country code." }
        hire_date:
          type: string
          description: |
            DATE. **Source mapping types as `MM/DD/YYY`** (3-digit year — likely
            typo for MM/DD/YYYY). Preserved verbatim; runtime is almost
            certainly 4-digit year.
        end_date: { type: string, description: "DATE — same MM/DD/YYY typo as hire_date." }
        grade_level: { type: string, description: "Lookup." }
        work_from_home: { type: string, enum: [Y, N], description: "Lookup." }
        primary_phone: { type: string, description: 'Client Label "Work Phone".' }
        mobile_number: { type: string }
        email: { type: string, format: email }
        total_office_days:
          type: number
          description: |
            Tango computes this as the sum of office_on_sun..sat regardless of
            the value sent in the JSON.
        office_on_sun: { type: number, description: "0 = no, 1 = yes." }
        office_on_mon: { type: number, description: "0 = no, 1 = yes." }
        office_on_tue: { type: number, description: "0 = no, 1 = yes." }
        office_on_wed: { type: number, description: "0 = no, 1 = yes." }
        office_on_thu: { type: number, description: "0 = no, 1 = yes." }
        office_on_fri: { type: number, description: "0 = no, 1 = yes." }
        office_on_sat: { type: number, description: "0 = no, 1 = yes." }
        cattr1:   { type: string }
        cattr2:   { type: string }
        cattr3:   { type: string }
        cattr4:   { type: string }
        cattr5:   { type: string }
        cattr6:   { type: string }
        cattr7:   { type: string }
        cattr8:   { type: string }
        cattr9:   { type: string }
        cattr10:  { type: string }
        nattr1:   { type: number }
        nattr2:   { type: number }
        nattr3:   { type: number }
        nattr4:   { type: number }
        nattr5:   { type: number }
        dattr1:   { type: string, description: "DATE (MM/DD/YYY per source)." }
        dattr2:   { type: string }
        dattr3:   { type: string }
        dattr4:   { type: string }
        dattr5:   { type: string }
        lovattr1: { type: string }
        lovattr2: { type: string }
        lovattr3: { type: string }
        lovattr4: { type: string }
        lovattr5: { type: string }
        brand_id: { type: number }
        seating_type: { type: string, description: "Lookup." }
        zip: { type: string }
        mac_addresses: { type: string, description: "Comma-separated MAC addresses." }
        network_user_names: { type: string, description: "Comma-separated aliases." }
        host_names: { type: string, description: "Comma-separated hostnames." }
    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 }
            processed_records: { type: integer }
            errors: { type: 'null' }
        - type: object
          required: [status, total_records, errors]
          properties:
            status: { type: string, const: ERROR }
            total_records: { type: integer }
            processed_records: { type: integer }
            error_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: []
