openapi: 3.1.0
info:
  title: Billing investigator
  version: 0.1.0
security: [{ desk: [] }]
paths:
  /investigations/{bill}:
    parameters:
      - { name: bill, in: path, required: true, schema: { type: string, format: uuid } }
    get:
      operationId: readInvestigation
      summary: Read the investigation against currently available billing evidence
      responses: &responses
        '200':
          description: Current investigation state
          content:
            application/json:
              schema: { $ref: '#/components/schemas/Investigation' }
        default:
          description: Operator access, evidence or journal unavailable
          content:
            application/problem+json:
              schema:
                type: object
                required: [status, code, title]
                properties:
                  status: { type: integer }
                  code: { type: string }
                  title: { type: string }
    put:
      operationId: startInvestigation
      summary: Start once for the same sealed comparison
      responses: *responses
    delete:
      operationId: stopInvestigation
      summary: Request cancellation for the current comparison
      responses: *responses
components:
  securitySchemes:
    desk: { type: http, scheme: bearer }
  schemas:
    Investigation:
      type: object
      required: [status]
      properties:
        status: { type: string, enum: [ready, running, completed, failed, cancelled, handoff, unchanged, tax-only] }
        reason: { type: string, enum: [first, cancelled, basis, retention, product, size, totals, unverified] }
        finding:
          type: object
          required: [index, claim]
          properties:
            index: { type: integer, minimum: 0 }
            claim: { type: string, enum: [change_only, last_discount_month] }
        evidence: { $ref: '#/components/schemas/Evidence' }
    Evidence:
      type: object
      required: [current, previous, number, previous_number, prices, gross_delta, reconciliation, changes]
      properties:
        current: { type: string, format: uuid }
        previous: { type: string, format: uuid }
        number: { type: string }
        previous_number: { type: string }
        seal: { type: string }
        previous_seal: { type: string }
        prices: { type: string }
        gross_delta: { type: string }
        reconciliation:
          type: object
          required: [previous_gross, current_gross, position_delta, additional_vat_delta]
          properties:
            previous_gross: { type: string }
            current_gross: { type: string }
            position_delta: { type: string }
            additional_vat_delta: { type: [string, 'null'], description: Additional VAT for net-priced positions. Null when included. }
        changes:
          type: array
          items:
            type: object
            required: [label, before, after, delta, old_lines, new_lines]
            properties:
              label: { type: string }
              before: { type: string }
              after: { type: string }
              delta: { type: string }
              old_lines: { type: array, items: { type: integer } }
              new_lines: { type: array, items: { type: integer } }
