swagger: "2.0"
info:
  description: "AvaL specification"
  version: "1.0.0"
  title: "AvaL API"
  termsOfService: "http://swagger.io/terms/"
  contact:
    email: "entwicklung@avalstandard.de"
  license:
    name: "Apache 2.0"
    url: "http://www.apache.org/licenses/LICENSE-2.0.html"
tags:
  - name: "AvaL API"
    description: "AvaL API"
    externalDocs:
      description: "Find out more about AvaL"
      url: "https://www.avalstandard.de/"
schemes:
  - "https"
paths:
  /avalmatchings:
    post:
      tags:
        - "AvaL Matchings"
      summary: "Create a new AvaL matching"
      description: ""
      operationId: "createAvalMatching"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - in: "body"
          name: "body"
          description: "AvaL matching which should be created"
          required: true
          schema:
            $ref: "#/definitions/AvalMatching"
      responses:
        200:
          description: "Successful operation."
        400:
          description: "The provided AvaL matching does not fulfill the specifications. Required parameters missing or provided AvaL state is invalid. Details may be included within the response body."
        409:
          description: "Provided AvaL matching ID is already in use."
        500:
          description: "An unexpected error occurred. Details may be included within the response body."
  /avalmatchings/{avalId}:
    patch:
      tags:
        - "AvaL Matchings"
      summary: "Update an existing AvaL matching"
      description: ""
      operationId: "updateAvalMatching"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "avalId"
          in: "path"
          description: "ID of AvaL matching that needs to be updated"
          required: true
          type: "string"
          format: "uuid"
        - in: "body"
          name: "body"
          description: "AvaL matching which should be updated."
          required: true
          schema:
            $ref: "#/definitions/AvalMatching"
      responses:
        200:
          description: "Successful operation."
        400:
          description: "Provided AvaL matching ID of the request body does not correspond to the matching ID within the URI path."
        404:
          description: "AvaL matching not found."
        405:
          description: "Validation exception because of incorrect state transition."
        500:
          description: "An unexpected error occurred. Details may be included within the response body."
  /avalmatchings/{avalId}/avaltransactions:
    post:
      tags:
        - "AvaL Transactions"
      summary: "Transactions of an AvaL matching"
      description: ""
      operationId: "createAvalTransaction"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "avalId"
          in: "path"
          description: "ID of the AvaL matching for the AvaL transactions."
          required: true
          type: "string"
          format: "uuid"
        - in: "body"
          name: "body"
          description: "AvaL transaction which should be created."
          required: true
          schema:
            $ref: "#/definitions/AvalTransaction"
      responses:
        200:
          description: "Successful operation."
        400:
          description: "The provided AvaL transaction does not fulfill the specifications. This may happen because the related AvaL matching is not in a corresponding state. Details may be included within the response body."
        409:
          description: "Provided AvaL transaction ID is already in use."
        500:
          description: "An unexpected error occurred. Details may be included within the response body."
  /avalmatchings/{avalId}/avaltransactions/{transactionId}:
    patch:
      tags:
        - "AvaL Transactions"
      summary: "Update an existing AvaL transaction"
      description: ""
      operationId: "updateAvalTransaction"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - name: "avalId"
          in: "path"
          description: "ID of AvaL matching which owns the transaction"
          required: true
          type: "string"
          format: "uuid"
        - name: "transactionId"
          in: "path"
          description: "ID of AvaL transaction which should be updated"
          required: true
          type: "string"
          format: "uuid"
        - in: "body"
          name: "body"
          description: "AvaL transaction which should be updated."
          required: true
          schema:
            $ref: "#/definitions/AvalTransaction"
      responses:
        200:
          description: "Successful operation."
        400:
          description: "Invalid state (wrong number), missing attributes or something else."
        404:
          description: "AvaL transaction not found."
        405:
          description: "Validation exception because of incorrect state transition."
        500:
          description: "An unexpected error occurred. Details may be included within the response body."
  /avalmatchings/{avalId}/avaltransactions/{transactionId}/avaldocuments:
    post:
      tags:
        - "AvaL Documents"
      summary: "Add a document to an existing AvaL transaction"
      description: "See https://tools.ietf.org/html/rfc7578 for further information about the multipart content type."
      operationId: "postAvalDocument"
      consumes:
        - "multipart/form-data"
      parameters:
        - name: "avalId"
          in: "path"
          description: "ID of AvaL matching which owns the transaction"
          required: true
          type: "string"
          format: "uuid"
        - name: "transactionId"
          in: "path"
          description: "ID of AvaL transaction which should be updated"
          required: true
          type: "string"
          format: "uuid"
        - in: "formData"
          name: "documentId"
          type: "string"
          format: "uuid"
          required: true
        - in: "formData"
          name: "filename"
          type: "string"
          required: true
        - in: "formData"
          name: "fileType"
          type: "integer"
          format: "int32"
          required: true
        - in: "formData"
          name: "fileFormat"
          type: "string"
          required: true
        - in: "formData"
          name: "file"
          type: "file"
          required: true
      responses:
        200:
          description: "Document successfully uploaded."
        400:
          description: "The provided AvaL document does not fulfill the specifications. Details may be included within the response body."
        409:
          description: "Provided AvaL document ID is already in use."
        500:
          description: "An unexpected error occurred. Details may be included within the response body."
definitions:
  AvalMatching:
    type: "object"
    required:
      - id
      - state
    properties:
      id:
        type: "string"
        format: "uuid"
      state:
        type: "integer"
        format: "int32"
        example: 1
        ## TODO one of
      client:
        $ref: "#/definitions/Client"
      supplier:
        $ref: "#/definitions/Supplier"
  Client:
    type: object
    properties:
      contractPartner:
        type: "string"
      material:
        type: "string"
        example: "Papier"
      containerType:
        type: "string"
        example: "MGB 1100 cbm"
      serviceType:
        type: "string"
        example: "Austausch"
      performancePlace:
        type: "string"
        example: "Musterstraße 43, 22041 Hamburg"
      materialUnit:
        type: "string"
        example: "to"
      serviceUnit:
        type: "string"
        example: "S"
      cycleInformation:
        type: "boolean"
        example: true
      cycleRythm:
        type: "string"
        example: "14-täglich"
  Supplier:
    type: "object"
    properties:
      contractPartner:
        type: "string"
        example: "Mustermann GmbH"
      material:
        type: "string"
        example: "Papier"
      containerType:
        type: "string"
        example: "MGB 1100 cbm"
      serviceType:
        type: "string"
        example: "Austausch"
      performancePlace:
        type: "string"
        example: "Musterstr. 43, D-22041 Hamburg"
      materialUnit:
        type: "string"
        example: "to"
      serviceUnit:
        type: "string"
        example: "S"
      cycleInformation:
        type: "boolean"
        example: true
      cycleRythm:
        type: "string"
        example: "14 täglich"
  AvalTransaction:
    type: "object"
    required:
      - id
      - state
    properties:
      id:
        type: "string"
        format: "uuid"
      state:
        type: "integer"
        format: "int32"
        maximum: 10
        minimum: 1
        example: 1
      avalId:
        type: "string"
        format: "uuid"
      operationPeriod:
        $ref: '#/definitions/Period'
      fulfillmentTimestamp:
        type: "string"
        format: "date-time"
      plannedFulfillmentPeriod:
        $ref: '#/definitions/Period'
      serviceAmount:
        type: "integer"
        format: "int32"
        example: 1
      containerAmount:
        type: "integer"
        format: "int32"
        example: 2
      materialAmount:
        type: "number"
        format: "double"
        example: 0.256
      isUnderMeasureThreshold:
        type: "boolean"
        example: false
      serviceNoteNumber:
        type: "string"
        example: "DL-4711"
      measureNoteNumber:
        type: "string"
        example: "WS-0815"
      governmentalAssetNumber:
        type: "string"
      governmentalCarrierNumber:
        type: "string"
      orderNumberSupplier:
        type: "string"
        example: "LFS_123456"
      orderNumberClient:
        type: "string"
        example: "ERP_987654"
      logisticComments:
        type: "string"
        example: "Bitte hinter dem Gebäude herum fahren!"
      cancellationReason:
        type: "string"
        example: "Tor verschlossen"
      complaintReason:
        type: "integer"
        format: "int32"
        minimum: 100
        maximum: 405
        example: 303
      variationNotes:
        type: "string"
      alternateAvalId:
        type: "string"
        format: "uuid"
      alternateMatchedAvalId:
        type: "string"
        format: "uuid"
  Period:
    type: "object"
    properties:
      start:
        type: "string"
        format: "date-time"
        example: "2019-07-01T14:00:00Z"
      end:
        type: "string"
        format: "date-time"
        example: "2019-07-01T18:00:00Z"
externalDocs:
  description: "Find out more about Swagger"
  url: "http://swagger.io"
