openapi: 3.1.0
info:
  title: api-invoicecache
  contact: {}
  license:
    name: MIT License
    url: https://opensource.org/licenses/MIT
  version: "4.1"
servers:
- url: http://localhost:64760
  description: Generated server url
paths:
  /{municipalityId}/scheduler/truncate:
    post:
      tags:
      - Scheduler Resource
      summary: Triggers scheduled job that verifies a file is eligible for truncation
        and truncates the file from database storage
      operationId: truncateFile
      parameters:
      - name: municipalityId
        in: path
        description: Municipality id
        required: true
        schema:
          type: string
        example: 2281
      responses:
        "200":
          description: Successful Operation
        "400":
          description: Bad Request
          content:
            application/problem+json:
              schema:
                oneOf:
                - $ref: "#/components/schemas/Problem"
                - $ref: "#/components/schemas/ConstraintViolationProblem"
        "500":
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
  /{municipalityId}/scheduler/transfer:
    post:
      tags:
      - Scheduler Resource
      summary: Triggers scheduled job that transfers a single file to Samba storage
      operationId: transferFile
      parameters:
      - name: municipalityId
        in: path
        description: Municipality id
        required: true
        schema:
          type: string
        example: 2281
      responses:
        "200":
          description: Successful Operation
        "400":
          description: Bad Request
          content:
            application/problem+json:
              schema:
                oneOf:
                - $ref: "#/components/schemas/Problem"
                - $ref: "#/components/schemas/ConstraintViolationProblem"
        "500":
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
  /{municipalityId}/invoices:
    get:
      tags:
      - Invoice Cache
      summary: Search for and fetch invoices
      operationId: getInvoices
      parameters:
      - name: municipalityId
        in: path
        description: Municipality id
        required: true
        schema:
          type: string
        example: 2281
      - name: request
        in: query
        required: true
        schema:
          $ref: "#/components/schemas/InvoiceFilterRequest"
      responses:
        "200":
          description: Successful Operation
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InvoicesResponse"
        "400":
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
        "500":
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
    post:
      tags:
      - Invoice Cache
      summary: Create/import an invoice
      operationId: importInvoice
      parameters:
      - name: municipalityId
        in: path
        description: Municipality id
        required: true
        schema:
          type: string
        example: 2281
      requestBody:
        content:
          application/json:
            schema:
              $ref: "#/components/schemas/InvoicePdfRequest"
        required: true
      responses:
        "201":
          description: Created
          content:
            '*/*': {}
        "400":
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
        "500":
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
  /{municipalityId}/import/samba-zips:
    post:
      tags:
      - Import Resource
      summary: Triggers a one-shot background import of historical invoice zips from
        the configured Samba sibling folder
      operationId: importSambaZips
      parameters:
      - name: municipalityId
        in: path
        description: Municipality id
        required: true
        schema:
          type: string
        example: 2281
      responses:
        "202":
          description: Accepted - import started
        "409":
          description: Conflict - another import is already running
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
        "400":
          description: Bad Request
          content:
            application/problem+json:
              schema:
                oneOf:
                - $ref: "#/components/schemas/Problem"
                - $ref: "#/components/schemas/ConstraintViolationProblem"
        "500":
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
  /{municipalityId}/invoices/{issuerLegalId}/{invoiceNumber}/pdfs:
    get:
      tags:
      - Invoice Cache
      summary: Download invoice PDFs as stream (single PDF or ZIP if multiple)
      operationId: downloadInvoicePdfs
      parameters:
      - name: municipalityId
        in: path
        description: Municipality id
        required: true
        schema:
          type: string
        example: 2281
      - name: issuerLegalId
        in: path
        required: true
        schema:
          type: string
      - name: invoiceNumber
        in: path
        required: true
        schema:
          type: string
      - name: debtorLegalId
        in: query
        description: Invoice debtor legal id
        required: false
        schema:
          type: string
          description: Invoice debtor legal id
      - name: invoiceId
        in: query
        description: Invoice id
        required: false
        schema:
          type: string
          description: Invoice id
      - name: invoiceFileName
        in: query
        description: Invoice file name
        required: false
        schema:
          type: string
          description: Invoice file name
      - name: invoiceType
        in: query
        description: Invoice type
        required: false
        schema:
          type: string
          description: Invoice type
          enum:
          - INVOICE
          - CREDIT_INVOICE
          - DIRECT_DEBIT
          - SELF_INVOICE
          - REMINDER
          - FINAL_INVOICE
          - CONSOLIDATED_INVOICE
      responses:
        "200":
          description: Successful Operation - Returns PDF or ZIP file
          content:
            '*/*':
              schema:
                $ref: "#/components/schemas/StreamingResponseBody"
        "404":
          description: No PDFs found
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
        "400":
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
        "500":
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
  /{municipalityId}/invoices/{issuerLegalId}/{invoiceNumber}/pdf:
    get:
      tags:
      - Invoice Cache
      summary: Fetch an invoice PDF via issuer legal id and invoice number
      operationId: getInvoicePdf
      parameters:
      - name: municipalityId
        in: path
        description: Municipality id
        required: true
        schema:
          type: string
        example: 2281
      - name: issuerLegalId
        in: path
        required: true
        schema:
          type: string
      - name: invoiceNumber
        in: path
        required: true
        schema:
          type: string
      - name: debtorLegalId
        in: query
        description: Invoice debtor legal id
        required: false
        schema:
          type: string
          description: Invoice debtor legal id
      - name: invoiceId
        in: query
        description: Invoice id
        required: false
        schema:
          type: string
          description: Invoice id
      - name: invoiceFileName
        in: query
        description: Invoice file name
        required: false
        schema:
          type: string
          description: Invoice file name
      - name: invoiceType
        in: query
        description: Invoice type
        required: false
        schema:
          type: string
          description: Invoice type
          enum:
          - INVOICE
          - CREDIT_INVOICE
          - DIRECT_DEBIT
          - SELF_INVOICE
          - REMINDER
          - FINAL_INVOICE
          - CONSOLIDATED_INVOICE
      responses:
        "200":
          description: "This endpoint is deprecated and will be removed in a future\
            \ version.use /{issuerLegalId}/{invoiceNumber}/pdfs instead"
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/InvoicePdf"
        "400":
          description: Bad Request
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
        "500":
          description: Internal Server Error
          content:
            application/problem+json:
              schema:
                $ref: "#/components/schemas/Problem"
      deprecated: true
  /api-docs:
    get:
      tags:
      - API
      summary: OpenAPI
      operationId: getApiDocs
      responses:
        "200":
          description: OK
          content:
            application/yaml:
              schema:
                type: string
      x-auth-type: None
      x-throttling-tier: Unlimited
      x-wso2-mutual-ssl: Optional
components:
  schemas:
    Problem:
      type: object
      properties:
        title:
          type: string
        detail:
          type: string
        instance:
          type: string
          format: uri
        type:
          type: string
          format: uri
        status:
          type: integer
          format: int32
    ConstraintViolationProblem:
      type: object
      properties:
        type:
          type: string
          format: uri
        status:
          type: integer
          format: int32
        violations:
          type: array
          items:
            $ref: "#/components/schemas/Violation"
        title:
          type: string
        detail:
          type: string
        causeAsProblem:
          $ref: "#/components/schemas/ThrowableProblem"
        instance:
          type: string
          format: uri
    ThrowableProblem:
      type: object
      properties:
        type:
          type: string
          format: uri
        title:
          type: string
        status:
          type: integer
          format: int32
        detail:
          type: string
        instance:
          type: string
          format: uri
        causeAsProblem: {}
    Violation:
      type: object
      properties:
        field:
          type: string
        message:
          type: string
    InvoicePdf:
      type: object
      description: Model for the InvoicePdf
      properties:
        content:
          type: string
          description: The file content as a BASE64-encoded string
          examples:
          - aGVsbG8gd29ybGQK
        name:
          type: string
          description: The filename
          examples:
          - test.pdf
      required:
      - content
      - name
    InvoicePdfRequest:
      type: object
      properties:
        issuerLegalId:
          type: string
          description: Invoice issuer legal id
        debtorLegalId:
          type: string
          description: Invoice debtor legal id
        invoiceNumber:
          type: string
          description: Invoice number
        invoiceId:
          type: string
          description: Invoice id
        invoiceType:
          type: string
          description: Invoice type
          enum:
          - INVOICE
          - CREDIT_INVOICE
          - DIRECT_DEBIT
          - SELF_INVOICE
          - REMINDER
          - FINAL_INVOICE
          - CONSOLIDATED_INVOICE
        attachment:
          $ref: "#/components/schemas/InvoicePdf"
          description: Attachment
      required:
      - attachment
    InvoiceFilterRequest:
      type: object
      description: Invoice filter request model
      properties:
        page:
          type: integer
          format: int32
          default: 1
          description: Page number
          examples:
          - 1
          minimum: 1
        limit:
          type: integer
          format: int32
          default: 100
          description: Result size per page
          examples:
          - 100
          maximum: 1000
          minimum: 1
        invoiceDateFrom:
          type: string
          format: date
          description: Fetch invoices from (and including) this date.
          examples:
          - 2022-01-01
        invoiceDateTo:
          type: string
          format: date
          description: "Fetch invoices up to (and including) this date, includes invoices\
            \ to this date"
          examples:
          - 2022-12-31
        dueDateFrom:
          type: string
          format: date
          description: Fetch invoices that are due from (and including) this date.
          examples:
          - 2022-01-01
        dueDateTo:
          type: string
          format: date
          description: Fetch invoices that are due up to (and including) this date
          examples:
          - 2022-12-31
        partyIds:
          type: array
          description: List of partyIds for organizations or private firms
          examples:
          - - fb2f0290-3820-11ed-a261-0242ac120002
            - fb2f0290-3820-11ed-a261-0242ac120003
          items:
            type: string
        ocrNumber:
          type: string
          description: Ocr number for the invoice
          examples:
          - "8907131234"
        invoiceNumbers:
          type: array
          description: Invoice numbers to fetch
          examples:
          - - "1234567"
            - "2345678"
          items:
            type: string
    Address:
      type: object
      description: Model for the Address
      properties:
        city:
          type: string
          description: City
          examples:
          - Sundsvall
        street:
          type: string
          description: Street address
          examples:
          - Storgatan 10
        postcode:
          type: string
          description: Postal code
          examples:
          - "85740"
        careOf:
          type: string
          description: Care of
          examples:
          - John Doe
    Invoice:
      type: object
      description: Model for the Invoice
      properties:
        customerName:
          type: string
          description: Customer name
          examples:
          - Fritjofs Blommor
        customerType:
          type: string
          description: Customer type
          examples:
          - XH
        invoiceNumber:
          type: string
          description: Invoice number
          examples:
          - "53489546"
        invoiceStatus:
          type: string
          description: Invoice status
          enum:
          - PAID
          - UNPAID
          - PARTIALLY_PAID
          - DEBT_COLLECTION
          - PAID_TOO_MUCH
          - REMINDER
          - SENT
          - VOID
          - UNKNOWN
          examples:
          - PAID
        ocrNumber:
          type: string
          description: OCR Number
          examples:
          - "8907136421"
        partyId:
          type: string
          description: PartyId for organization or private firm
          examples:
          - fb2f0290-3820-11ed-a261-0242ac120002
        invoiceDescription:
          type: string
          description: Invoice description
          examples:
          - Barn och Utbildning
        invoiceDueDate:
          type: string
          format: date
          description: When the invoice is due to be paid
          examples:
          - 2022-05-05
        invoiceDate:
          type: string
          format: date
          description: When the invoice was created
          examples:
          - 2022-04-05
        invoiceReminderDate:
          type: string
          format: date
          description: When a reminder was sent out
          examples:
          - 2022-04-05
        paidAmount:
          type: number
          description: Amount already paid on the invoice.
          examples:
          - 4995.0
        totalAmount:
          type: number
          description: Amount to pay including VAT (SEK)
          examples:
          - 4995.0
        invoiceFileName:
          type: string
          description: "Filename of the invoice, if it is present"
          examples:
          - Faktura_5555555_to_9988776655.pdf
        vat:
          type: number
          description: Vat amount in SEK
          examples:
          - 999.0
        amountVatExcluded:
          type: number
          description: Amount without vat
          examples:
          - 3996.0
        invoiceType:
          type: string
          description: Invoice type
          enum:
          - INVOICE
          - CREDIT_INVOICE
          - DIRECT_DEBIT
          - SELF_INVOICE
          - REMINDER
          - FINAL_INVOICE
          - CONSOLIDATED_INVOICE
          examples:
          - NORMAL or CREDIT
        invoiceAddress:
          $ref: "#/components/schemas/Address"
    InvoicesResponse:
      type: object
      description: Response with invoices
      properties:
        invoices:
          type: array
          items:
            $ref: "#/components/schemas/Invoice"
        _meta:
          $ref: "#/components/schemas/MetaData"
          readOnly: true
    MetaData:
      type: object
      description: Metadata model
      properties:
        page:
          type: integer
          format: int32
          description: Current page
          examples:
          - 5
          readOnly: true
        limit:
          type: integer
          format: int32
          description: Displayed objects per page
          examples:
          - 20
          readOnly: true
        count:
          type: integer
          format: int32
          description: Displayed objects on current page
          examples:
          - 13
          readOnly: true
        totalRecords:
          type: integer
          format: int64
          description: Total amount of hits based on provided search parameters
          examples:
          - 98
          readOnly: true
        totalPages:
          type: integer
          format: int32
          description: Total amount of pages based on provided search parameters
          examples:
          - 23
          readOnly: true
    StreamingResponseBody: {}
  securitySchemes: {}
