openapi: 3.0.3
info:
  title: CentraQuest Integration API
  version: 2.0.0
  description: Unified integration API for Abacus, Sage50 and Accounto.
servers:
  - url: /api/integration/v2
paths:
  /tenants/{tenant_id}/providers/{provider}/invoices:export:
    post:
      summary: Export invoice to provider
      parameters:
        - in: path
          name: tenant_id
          required: true
          schema:
            type: string
        - in: path
          name: provider
          required: true
          schema:
            type: string
            enum: [abacus, sage50, accounto]
        - in: header
          name: Idempotency-Key
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/InvoiceExportRequest'
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobAccepted'
        '400':
          description: Bad request
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
  /tenants/{tenant_id}/providers/{provider}/addresses:export:
    post:
      summary: Export addresses to provider
      parameters:
        - in: path
          name: tenant_id
          required: true
          schema:
            type: string
        - in: path
          name: provider
          required: true
          schema:
            type: string
            enum: [abacus, sage50, accounto]
        - in: header
          name: Idempotency-Key
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AddressExportRequest'
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobAccepted'
  /tenants/{tenant_id}/providers/{provider}/master-data:import:
    post:
      summary: Import provider master data
      parameters:
        - in: path
          name: tenant_id
          required: true
          schema:
            type: string
        - in: path
          name: provider
          required: true
          schema:
            type: string
            enum: [abacus, sage50, accounto]
        - in: header
          name: Idempotency-Key
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MasterDataImportRequest'
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobAccepted'
  /tenants/{tenant_id}/providers/{provider}/payments:import:
    post:
      summary: Import payment status from provider
      parameters:
        - in: path
          name: tenant_id
          required: true
          schema:
            type: string
        - in: path
          name: provider
          required: true
          schema:
            type: string
            enum: [abacus, sage50, accounto]
        - in: header
          name: Idempotency-Key
          required: true
          schema:
            type: string
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PaymentImportRequest'
      responses:
        '202':
          description: Accepted
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobAccepted'
  /jobs/{job_id}:
    get:
      summary: Get job status
      parameters:
        - in: path
          name: job_id
          required: true
          schema:
            type: string
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/JobStatus'
        '404':
          description: Not found
          content:
            application/problem+json:
              schema:
                $ref: '#/components/schemas/Problem'
components:
  schemas:
    InvoiceExportRequest:
      type: object
      required: [client_accounting, invoice_id, booking_type]
      properties:
        client_accounting:
          type: string
        invoice_id:
          type: string
        booking_type:
          type: string
          enum: [creditor, debitor]
        options:
          type: object
          additionalProperties: true
    AddressExportRequest:
      type: object
      required: [client_accounting]
      properties:
        client_accounting:
          type: string
        address_ids:
          type: array
          items:
            type: string
    MasterDataImportRequest:
      type: object
      required: [client_accounting, domains]
      properties:
        client_accounting:
          type: string
        domains:
          type: array
          items:
            type: string
            enum: [addresses, accounts, taxes, banks, currencies, payment_terms, cost_centers, plants]
        incremental_since:
          type: string
          format: date-time
    PaymentImportRequest:
      type: object
      required: [client_accounting]
      properties:
        client_accounting:
          type: string
        incremental_since:
          type: string
          format: date-time
    JobAccepted:
      type: object
      required: [job_id, state]
      properties:
        job_id:
          type: string
        state:
          type: string
          enum: [queued]
    JobStatus:
      type: object
      required: [job_id, provider, operation, state, created_at, updated_at]
      properties:
        job_id:
          type: string
        provider:
          type: string
          enum: [abacus, sage50, accounto]
        operation:
          type: string
        state:
          type: string
          enum: [queued, running, succeeded, failed, partially_succeeded, dead_lettered]
        progress:
          type: integer
          minimum: 0
          maximum: 100
        errors:
          type: array
          items:
            type: object
            additionalProperties: true
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
    Problem:
      type: object
      required: [type, title, status, detail]
      properties:
        type:
          type: string
        title:
          type: string
        status:
          type: integer
        detail:
          type: string
        instance:
          type: string
        correlation_id:
          type: string
        provider_error:
          type: object
          additionalProperties: true
