openapi: 3.0.0
info:
  title: O2 SK SAFE API
  description: API for uploading files from an external party
  version: 0.0.1

servers:
  - url: https://tst.safe.o2.sk/api
    description: Test server
  - url: https://safe.o2.sk/api
    description: Main (production) server

security:
  - oAuth:
      - https://safe.o2.sk/.default

paths:
  /account-switchings:
    post:
      tags: [account-switchings]
      summary: Upload a new switching request
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  description: file upload with a filename
                  type: string
                  format: binary

      responses:
        201:
          description: Account switching request has been created
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/AccountSwitching"
                  - properties:
                      status:
                        example: IN_PROGRESS

        400:
          description: Input validation failed.
        401:
          description: Authentication error
        403:
          description: Client ID unauthorized
        422:
          description: Prohibited file format.

    get:
      tags: [account-switchings]
      summary: Retrieve all switching requests
      parameters:
        - in: query
          name: status
          description: only return switchings with this status
          schema:
            $ref: "#/components/schemas/AccountSwitchingStatus"
        - in: query
          name: page
          schema:
            type: integer
            default: 1

      responses:
        200:
          description: Switching requests matching parameters. Ordered by created_at, newest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      anyOf:
                        - $ref: "#/components/schemas/AccountSwitching"
                        - allOf:
                            - $ref: "#/components/schemas/AccountSwitching"
                            - example:
                                id: ba5ef478-aa00-453b-a58d-3619b7dadf3f
                                status: DONE
                                original_filename: switching-2022-03-21.xls
                                created_at: "2022-03-21T10:08:42.526Z"
                                updated_at: "2022-03-21T14:07:44.526Z"
                    maxItems: 10
                  meta:
                    type: object
                    properties:
                      current_page:
                        type: integer
                        example: 3
                      last_page:
                        type: integer
                        example: 3
        400:
          description: Invalid value for page or status

  /account-switchings/{id}:
    get:
      tags: [account-switchings]
      summary: Retrieve an existing switching request
      parameters:
        - in: path
          schema:
            type: string
          name: id
          required: true

      responses:
        200:
          description: Switching request
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/AccountSwitching"
        404:
          description: Not found
  
  /uploads:
    post:
      tags: [uploads]
      summary: Upload a new file
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  description: file upload with a filename
                  type: string
                  format: binary

      responses:
        201:
          description: File has been uploaded
          content:
            application/json:
              schema:
                allOf:
                  - $ref: "#/components/schemas/File"
                  - properties:
                      status:
                        example: IN_PROGRESS

        400:
          description: Input validation failed.
        401:
          description: Authentication error
        403:
          description: Client ID unauthorized
        422:
          description: Prohibited file format.

    get:
      tags: [uploads]
      summary: Retrieve all file uploads
      parameters:
        - in: query
          name: clientId
          description: only return files uploaded from this clientId
          schema:
            format: uuid
            type: string
            example: 54734353-2414-4a81-b9db-e27c0089cb5a
        - in: query
          name: page
          schema:
            type: integer
            default: 1

      responses:
        200:
          description: Uploaded files matching parameters. Ordered by created_at, newest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      anyOf:
                        - $ref: "#/components/schemas/File"
                        - allOf:
                            - $ref: "#/components/schemas/File"
                            - example:
                                id: ba5ef478-aa00-453b-a58d-3619b7dadf3f
                                original_filename: file-2022-03-21.xls
                                created_at: "2022-03-21T10:08:42.526Z"
                                url: https://example.com/
                    maxItems: 10
                  meta:
                    type: object
                    properties:
                      current_page:
                        type: integer
                        example: 3
                      last_page:
                        type: integer
                        example: 3
        400:
          description: Invalid value for page
        403:
          description: Not authorized

  /uploads/{id}:
    delete:
      tags: [uploads]
      summary: Delete uploaded file
      parameters:
        - in: path
          schema:
            type: string
          name: id
          required: true
      responses:
        204:
          description: Deletion successful
        403: 
          description: Not authorized        
        404:
          description: Not found

  /mnp-snapshots:
    post: 
      tags: [mnp-snapshots]
      summary: Upload a new mnp snapshot
      requestBody:
        required: true
        content:
          multipart/form-data:
            schema:
              type: object
              properties:
                file:
                  description: mnp-snapshot upload with a filename
                  type: string
                  format: binary
      responses:
        201:
          description: Mnp snapshot has been uploaded
          content:
            application/json:
              schema:
                allOf:
                  - type: object
                    properties:
                      id:
                        format: uuid
                        type: string
                        example: 54734353-2414-4a81-b9db-e27c0089cb5a


        400:
          description: Input validation failed.
        401:
          description: Authentication error
        403:
          description: Client ID unauthorized

    get:
      tags: [mnp-snapshots]
      summary: Retrieve all mnp snapshots

      responses:
        200:
          description: Mnp snapshots ordered by created_at, newest first
          content:
            application/json:
              schema:
                type: object
                properties:
                  data:
                    type: array
                    items:
                      anyOf:
                        - $ref: "#/components/schemas/MnpSnapshot"
                        - allOf:
                            - $ref: "#/components/schemas/MnpSnapshot"
                            - example:
                                id: 54734353-2414-4a81-b9db-e27c0089cb5a
                                filename: mnp-snapshot-2022-03-22.xls
                                created_at: "2022-03-22T10:03:42.526Z"
                                url: https://example.com/

  /mnp-snapshots/{id}:
    delete:
      tags: [mnp-snapshots]
      summary: Delete uploaded mnp snapshot
      parameters:
        - in: path
          schema:
            type: string
          name: id
          required: true
      responses:
        204:
          description: Deletion successful
        403: 
          description: Not authorized        
        404:
          description: Not found

components:
  securitySchemes:
    oAuth:
      type: oauth2
      description: This API uses OAuth 2 with the client credentials flow
      flows:
        clientCredentials:
          tokenUrl: https://login.microsoftonline.com/b287c0b1-6968-4dc8-9732-8d00f2760e89/oauth2/v2.0/token
          scopes:
            https://safe.o2.sk/.default: default scope for this API

  schemas:
    AccountSwitchingStatus:
      type: string
      enum:
        - IN_PROGRESS
        - DONE
      example: DONE

    AccountSwitching:
      type: object
      properties:
        id:
          format: uuid
          type: string
        original_filename:
          type: string
        status:
          $ref: "#/components/schemas/AccountSwitchingStatus"
        createdAt:
          type: string
          format: date-time
        updatedAt:
          type: string
          format: date-time
      example:
        id: 54734353-2414-4a81-b9db-e27c0089cb5a
        status: IN_PROGRESS
        original_filename: switching-2022-03-22.xls
        created_at: "2022-03-22T10:03:42.526Z"
        updated_at: "2022-03-22T10:03:42.526Z"

    File: 
      type: object
      properties:
        id:
          format: uuid
          type: string
        original_filename:
          type: string
        createdAt:
          type: string
          format: date-time
      example:
        id: 54734353-2414-4a81-b9db-e27c0089cb5a
        original_filename: file-2022-03-22.xls
        created_at: "2022-03-22T10:03:42.526Z"
        url: https://example.com/

    MnpSnapshot:
      type: object
      properties:
        id:
          format: uuid
          type: string
        original_filename:
          type: string
        createdAt:
          type: string
          format: date-time
      example:
        id: 54734353-2414-4a81-b9db-e27c0089cb5a
        filename: mnp-snapshot-2022-03-22.xls
        created_at: "2022-03-22T10:03:42.526Z"
        url: https://example.com/