openapi: 3.1.0
info:
  title: Tango Total Approved Budget Inbound API
  version: "0.4"
  description: |
    Async REST API for inbound posting of approved budget totals from a client
    system into Tango. The same payload supports both Project and Lease budget
    updates — the `lease_num` / `project_num` fields determine which branch
    applies. Async pattern: PUT returns a `gu_id`; the client polls
    `/v1/batch/status` until COMPLETED or ERROR.

    Update semantics: a `total` sent after the initial payload is **added** to
    the existing amount (cumulative).
  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: Budget Inbound
  - name: Status
paths:
  /v1/projectmgmt/batch/budgets:
    put:
      summary: Submit approved budget records (async)
      operationId: putBudgetsBatch
      tags: [Budget Inbound]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/BudgetBatchRequest"
            examples:
              project:
                summary: Project budget record
                value:
                  records:
                    - header_created_date: "03/20/2012"
                      header_last_updated_date: "03/20/2025"
                      header_requested_by: "John Doe"
                      header_status: "APPROVED"
                      lease_num: ""
                      project_num: "A64390"
                      line_item_seq: 10
                      client_ref_num: 429
                      total: 1000000
              lease:
                summary: Lease budget record
                value:
                  records:
                    - header_created_date: "03/20/2012"
                      header_last_updated_date: "03/20/2025"
                      header_requested_by: "John Doe"
                      header_status: "APPROVED"
                      lease_num: "L89096"
                      project_num: ""
                      line_item_seq: ""
                      client_ref_num: ""
                      total: 1440000
      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: Processing 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:
    BudgetBatchRequest:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/BudgetRecord"
    BudgetRecord:
      type: object
      description: |
        Required-field set depends on whether the record targets a Project or
        a Lease. Both modes require `header_last_updated_date`, `header_status`,
        and `total`. Project mode additionally requires `header_created_date`,
        `project_num`, and (either `line_item_seq` or `client_ref_num`). Lease
        mode requires `lease_num`. OAS 3.1 cannot natively express conditional
        required-fields this rich; the runtime validation rules are noted in the
        companion Markdown and validation table.
      required:
        - header_last_updated_date
        - header_status
        - total
      properties:
        header_created_date:
          type: string
          description: "MM/DD/YYYY. Required for Project mode."
        header_last_updated_date:
          type: string
          description: "MM/DD/YYYY. Required for both Project and Lease."
        header_requested_by:
          type: string
        header_status:
          type: string
          enum: [APPROVED]
          description: Only `APPROVED` is accepted.
        lease_num:
          type: string
          description: Required for Lease mode (mutually exclusive with project_num).
        project_num:
          type: string
          description: Required for Project mode.
        line_item_seq:
          oneOf:
            - { type: number }
            - { type: string, maxLength: 0 }
          description: |
            Project mode: one of `line_item_seq` / `client_ref_num` must be
            sent. When sent, must be unique within the project.
        client_ref_num:
          oneOf:
            - { type: number }
            - { type: string, maxLength: 0 }
          description: |
            Project mode: one of `line_item_seq` / `client_ref_num` must be
            sent (also unique within project).
        total:
          type: number
          description: |
            Aggregate budget total. ONE record per project / lease. Subsequent
            payloads are added to the existing amount (cumulative).
    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: 'null' }
                  error: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
