openapi: 3.1.0
info:
  title: Tango Lease Inbound API
  version: "0.5"
  description: |
    Async REST API: client inserts / updates lease records (and child entities:
    Basic Info, Options & Terms, Contacts, Recurring Costs, Allocations,
    Obligations, Clauses) in Tango. Async pattern: PUT returns gu_id; client
    polls /v1/batch/status.

    Identification key: either `lease_id` (Tango internal) or the combination
    of `lease_number` + `country` + `brand_id`. If the lease does not exist,
    an error is returned (this integration updates only).

    The source design doc does NOT include the request-body schema — the field
    list lives in tab-specific child entities and is referenced indirectly via
    validations. The YAML defines the request shape generically with
    `additionalProperties: true` and captures the validations explicitly.
  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: Leases
  - name: Status
paths:
  /v1/leasemgmt/batch/leases:
    put:
      summary: Insert/update lease records (async)
      operationId: putLeasesBatch
      tags: [Leases]
      parameters:
        - $ref: "#/components/parameters/XClient"
        - $ref: "#/components/parameters/XApiKey"
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/LeaseBatchRequest"
      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:
    LeaseBatchRequest:
      type: object
      required: [records]
      properties:
        records:
          type: array
          items:
            $ref: "#/components/schemas/LeaseRecord"
    LeaseRecord:
      type: object
      description: |
        Lease record. The source design doc does not define a full field
        schema — only validations. Treat this as a permissive document
        envelope; runtime validation rules (see Markdown) enforce the contract.
      additionalProperties: true
      properties:
        lease_id:
          type: string
          description: Tango-internal lease identifier (one of lease_id / lease_number+country+brand_id required).
        lease_number:
          type: string
          description: Client-defined lease number.
        country:
          type: string
          description: Required if identifying via lease_number.
        brand_id:
          type: string
          description: Required if identifying via lease_number.
        legal_entity: { type: string }
        lease_type_code: { type: string }
        lease_financials_group: { type: string }
        lease_acct_classification: { type: string }
        disposition_type: { type: string }
        lease_portfolio_type: { type: string }
        currency_code: { type: string }
        tenancy_type: { type: string }
        area_measure: { type: string }
        rent_prorate_method: { type: string }
        term_status: { type: string }
        options:
          type: array
          description: |
            When present, each entry must include `option_term` and
            `option_status`. Other fields validated per the Markdown.
          items:
            type: object
            additionalProperties: true
        contacts:
          type: array
          items:
            type: object
            additionalProperties: true
        recurring_costs:
          type: array
          items:
            type: object
            additionalProperties: true
        allocations:
          type: array
          items:
            type: object
            additionalProperties: true
            required: [alloc_supplier_site_number, allocation_percentage]
            properties:
              alloc_supplier_site_number: { type: string }
              allocation_percentage: { type: number }
        obligations:
          type: array
          items:
            type: object
            additionalProperties: true
            required: [obl_type]
            properties:
              obl_type: { type: string }
        clauses:
          type: array
          items:
            type: object
            additionalProperties: true
            required: [clause_type]
            properties:
              clause_type: { 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 }
                  error: { type: string }
security:
  - xClientHeader: []
    xApiKeyHeader: []
