openapi: 3.1.0
info:
  title: Tango User Roles Reconcile API (non-BU)
  version: "0.7"
  description: |
    Async outbound REST API: client retrieves Tango user accounts with their
    provisioning state for reconciliation. Same endpoint as the BU variant
    (`/v1/usermgmt/batch/users` GET). Filter via `user_name` or `status`.

    Differences from the BU variant:
      - No BU layer (no `default_bu`, no `bu[]` array).
      - Country access lives directly inside the user record under
        `countries[].country` / `regions` / `roles` / `entity_security[]`.
      - Page size 5000 (BU variant uses 1000).

    Same once-per-day batch-refresh constraint as the BU variant.
  x-direction: outbound
  x-source: Tango
  x-destination: Client System
servers:
  - url: https://api.tangoanalytics.com
    description: Production
  - url: https://testapi.tangoanalytics.com
    description: Test (SIT/UAT)
tags:
  - name: User Reconcile
  - name: Status
paths:
  /v1/usermgmt/batch/users:
    get:
      summary: Initiate user reconcile export (async)
      operationId: getUsersReconcileNonBU
      tags: [User Reconcile]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: status
          required: false
          schema:
            type: string
            enum: [A, N]
        - in: query
          name: user_name
          required: false
          schema: { type: string }
      responses:
        "200":
          description: Async ack with gu_id.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AcceptedResponse"
  /v1/batch/status:
    get:
      summary: Retrieve paginated user records by gu_id
      operationId: getUsersReconcileByGuId
      tags: [Status]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
        - in: query
          name: gu_id
          required: true
          schema: { type: string, format: uuid }
        - in: query
          name: page_no
          required: false
          schema: { type: integer, minimum: 1 }
      responses:
        "200":
          description: Paginated user records.
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/UserPage"
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:
    AcceptedResponse:
      type: object
      required: [status]
      properties:
        status: { type: string, enum: [OK, Error] }
        status_message: { type: string }
        gu_id: { type: string, format: uuid }
    UserPage:
      type: object
      required: [status, records]
      properties:
        status: { type: string, enum: [PROCESSING, COMPLETED, ERROR] }
        total_records: { type: integer }
        total_pages: { type: integer }
        page_size: { type: integer, default: 5000 }
        page_no: { type: integer }
        records:
          type: array
          items:
            $ref: "#/components/schemas/UserRecord"
    UserRecord:
      type: object
      additionalProperties: true
      properties:
        user_name: { type: string }
        first_name: { type: string }
        last_name: { type: string }
        email: { type: string, format: email }
        user_type:
          type: string
          enum: [CONTRACTOR, CORPORATE, GENERAL_USER]
        sso:
          type: string
          enum: [Y, N]
        status:
          type: string
          enum: [A, N]
        default_country: { type: string }
        data_access_level:
          type: string
          enum: [F, R, RR]
        brands:
          type: string
          description: |
            Comma-separated brand names. Per the source sample, this is a
            flat string at the user level — different shape from the
            BU variant's nested-object array.
        countries:
          type: array
          items:
            type: object
            properties:
              country:
                type: string
                description: ISO 3-letter code.
              regions:
                type: string
                description: "`ALL` or comma-separated region identifiers."
              roles:
                type: string
                description: Configured client role name(s).
              entity_security:
                type: array
                items:
                  type: object
                  properties:
                    entity_type:
                      type: string
                      description: "TARGET, SITE, STORE, PROJECT, LEASE, etc."
                    full_access:
                      type: string
                      enum: [Y, N]
                    restrictions:
                      type: array
                      items:
                        type: object
                        properties:
                          attribute:
                            type: string
                            enum: [SEC_ATTR1, SEC_ATTR2]
                          value: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
