openapi: 3.0.0
info:
  title: Material Supplier Integration API
  version: 0.2-oas3
  contact:
    name: Scalepoint
    url: 'https://dev.scalepoint.com'
    email: dev@scalepoint.com
tags:
  - name: material-supplier
    description: API for external material suppliers
paths:
  '/{version}/material/validateaccount':
    post:
      tags:
        - material-supplier
      summary: Validate Service Partner account
      operationId: validateAccount
      parameters:
        - name: version
          in: path
          description: API version
          required: true
          schema:
            type: string
            enum:
              - v1
            default: v1
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ValidateAccountResponse'
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ValidateAccountRequest'
        required: true
  '/{version}/material/order':
    post:
      tags:
        - material-supplier
      summary: Create material order
      operationId: materialOrder
      parameters:
        - name: version
          in: path
          description: API version
          required: true
          schema:
            type: string
            enum:
              - v2
            default: v2
      responses:
        '200':
          description: OK
        '400':
          description: Bad Request
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '401':
          description: Unauthorized
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '404':
          description: Not Found
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
        '500':
          description: Internal Server Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ErrorResponse'
      requestBody:
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/MaterialOrderRequest'
        description: Material order payload
        required: true
servers:
  - url: https://entry.scalepoint.com/ecx/host/api/integration
    description: Production server (uses live data)
  - url: https://test.scalepoint.com/ecx/host/api/integration
    description: Test server (uses dummy data but has the same setup and version as Production)
security:
  - bearerAuth: []
components:
  securitySchemes:
      bearerAuth:
        type: http
        scheme: bearer
        bearerFormat: JWT
  schemas:
    ValidateAccountRequest:
      type: object
      properties:
        meta:
          type: object
          properties:
            timestamp:
              type: string
          required:
            - timestamp
        data:
          type: object
          properties:
            tenant:
              description: Insurance company alias in Scalepoint
              type: string
            companyTaxId:
              description: Service Partner's CVR
              type: string
            referenceNumber:
              description: Reference number for the claim in Scalepoint
              type: string
          required:
            - tenant
            - companyTaxId
            - referenceNumber
      required:
        - meta
        - data
    ValidateAccountResponse:
      type: object
      properties:
        meta:
          type: object
          properties:
            timestamp:
              type: string
          required:
            - timestamp
        data:
          type: object
          properties:
            claim:
              type: object
              properties:
                id:
                  type: string
                damageCause:
                  type: string
                damageCategory:
                  type: string
                tenant:
                  type: string
                number:
                  type: string
                damageAddress:
                  type: object
                  properties:
                    street:
                      type: string
                    street2:
                      type: string
                    postalCode:
                      type: string
                    city:
                      type: string
                  required:
                    - street
                    - postalCode
                    - city
              required:
                - id
                - damageCause
                - damageCategory
                - tenant
                - number
                - damageAddress
            service:
              type: object
              properties:
                referenceNumber:
                  type: string
                id:
                  type: string
                startDate:
                  type: string
                estimatedEndDate:
                  type: string
                actualEndDate:
                  type: string
              required:
                - referenceNumber
                - id
                - startDate
                - estimatedEndDate
            servicePartners:
              type: array
              items:
                $ref: '#/components/schemas/ServicePartnerItem'
          required:
            - claim
            - service
            - servicePartners
      required:
        - meta
        - data
    MaterialOrderRequest:
      type: object
      properties:
        meta:
          type: object
          properties:
            timestamp:
              type: string
          required:
            - timestamp
        data:
          type: object
          properties:
            order:
              type: object
              properties:
                number:
                  type: string
                subtotal:
                  type: number
                  description: Can be negative
                vat:
                  type: number
                  description: Can be negative
                total:
                  type: number
                  description: Can be negative
                items:
                  type: array
                  items:
                    $ref: '#/components/schemas/OrderItem'
              required:
                - number
                - subtotal
                - vat
                - total
                - items
            claim:
              type: object
              properties:
                id:
                  type: string
                tenant:
                  type: string
              required:
                - id
                - tenant
            servicePartner:
              type: object
              properties:
                id:
                  type: string
              required:
                - id
          required:
            - order
            - claim
            - servicePartner
      required:
        - meta
        - data
    ErrorResponse:
      type: object
      properties:
        meta:
          type: object
          properties:
            timestamp:
              type: string
          required:
            - timestamp
        data:
          type: object
          properties:
            error:
              type: string
          required:
            - error
      required:
        - meta
        - data
    OrderItem:
      type: object
      properties:
        lineNumber:
          type: integer
        id1:
          type: string
        id2:
          type: string
        title:
          type: string
        unit:
          type: string
          description: >-
            Possible values: None, Pcs, Hours, Days, Kilograms, Liters, Meters,
            SquareMeters, CubicMeters, Lbm, Sum, Tonnes, Bags, Kilometers,
            CubicMetersDays
        quantity:
          type: integer
          description: Can be negative
        unitPrice:
          type: number
          description: Can be negative
        discount:
          type: integer
          minimum: 0
          maximum: 100
        subtotal:
          type: number
          description: Can be negative
        status:
          type: string
          description: 'Possible values: Ordered, Delivered, Invoiced, Canceled'
      required:
        - lineNumber
        - id1
        - title
        - unit
        - quantity
        - unitPrice
        - discount
        - subtotal
        - status
    ServicePartnerItem:
      type: object
      properties:
        id:
          type: string
        displayName:
          type: string
        companyTaxId:
          type: string
        phoneNumber:
          type: string
        faxNumber:
          type: string
        responsibleUser:
          type: string
      required:
        - id
        - displayName
        - companyTaxId