swagger: "2.0"

info:
  version: 1.0.0
  title: Asset Transcoder API Specifications
schemes:
  - https
host: qa-ows-assset-transcoder.theorchard.io
paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK
          examples:
            application/json: { "status": "ok" }

  /upload-token:
    get:
      tags:
        - "assets"
      description: Generate credentials for input asset upload.
      responses:
        '200':
          description: 200 OK
          schema:
            example:
              bucket: dev-orcd-transcoder-input-assets
              credentials:
                aws_access_key_id: AKIAIOSFODNN7EXAMPLE
                aws_secret_access_key: wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY
                expiration: '2016-01-25T19:55:29.611Z'
                token: >-
                  AQoEXAMPLEH4aoAH0gNCAPyJxz4BlCFFxWNE1OPTgk5TthT+FvwqnKwRcOIfrRh3c/L
              filename: hjhj45_rfwri_424524

  /uploads:
    post:
      tags:
        - "assets"
      summary: "Update asset_upload with file's metadata, is invoked by acknowledge lambda."
      operationId: "post_asset"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - in: "body"
          name: "body"
          description: "Uploaded file metadata"
          required: true
          schema:
            $ref: "#/definitions/AssetUploadUpdate"
      responses:
        200:
          description: "200 OK"
          schema:
            $ref: "#/definitions/AssetUpload"
        400:
          description: "400 Bad Request"
        404:
          description: "404 Not found"

    delete:
      tags:
        - "assets"
      summary: "Soft delete asset upload by provided filename"
      operationId: "delete_asset"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - in: "body"
          name: "body"
          description: "Asset's data"
          required: true
          schema:
            $ref: "#/definitions/AssetUploadDelete"
      responses:
        200:
          description: "200 OK"
          schema:
            $ref: "#/definitions/AssetUpload"
        400:
          description: "400 Bad Request"
        404:
          description: "404 Not found"

  /status:
    post:
      tags:
        - "assets"
      summary: "Create new status for uploaded asset"
      operationId: "post_asset_general_status"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - in: "body"
          name: "body"
          description: "New status data"
          required: true
          schema:
            $ref: "#/definitions/AssetStatusUpdate"
      responses:
        200:
          description: "200 OK"
          schema:
            $ref: "#/definitions/AssetStatus"
        400:
          description: "400 Bad Request"
        404:
          description: "404 Not found"

  /final:
    post:
      tags:
        - "assets"
      summary: "Create new status and asset final"
      operationId: "post_asset_final"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - in: "body"
          name: "body"
          description: "New status data with final assets"
          required: true
          schema:
            $ref: "#/definitions/AssetFinalUpdate"
      responses:
        200:
          description: "200 OK"
          schema:
            $ref: "#/definitions/AssetStatus"
        400:
          description: "400 Bad Request"
        404:
          description: "404 Not found"

  /status/{filename}:
    get:
      tags:
        - "assets"
      summary: "Get the status of an upload"
      operationId: "get_asset_status"
      consumes:
        - "application/json"
      produces:
        - "application/json"
      parameters:
        - in: "path"
          name: "filename"
          description: "Filename with extension"
          required: true
          type: "string"
      responses:
        200:
          description: "200 OK"
          examples:
            application/json: {
              "id": 4,
              "asset_upload_id": 31,
              "status": "validation_complete",
              "description": "",
              "created_date": 1573900680.0,
              "message": {
                "function": "encoding-images-validation",
                "status": "validation_complete",
                "input": {
                  "key": "47d84a8a_2bc6_4f81_ac12_5fef3f2bce43.jpg",
                  "bucket": "qa-orcd-transcoder-input-assets",
                  "file_type": "jpeg",
                  "transcoding_type": "image"
                }
              }
            }
        400:
          description: "400 Bad Request"
        404:
          description: "404 Not found"

definitions:
  AssetUpload:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      user_id:
        type: "string"
      asset_type:
        type: "string"
      filename:
        type: "string"
      object_id:
        type: "string"
      object_type:
        type: "string"
      bucket:
        type: "string"
      original_filename:
        type: "string"
      deleted:
        type: "integer"
        enum: [0, 1]
  AssetUploadUpdate:
    type: "object"
    properties:
      object_id:
        type: "string"
      object_type:
        type: "string"
      filename:
        type: "string"
      original_filename:
        type: "string"
      asset_type:
        type: "string"
  AssetUploadDelete:
    type: "object"
    properties:
      object_id:
        type: "string"
      object_type:
        type: "string"
      asset_type:
        type: "string"
  AssetStatus:
    type: "object"
    properties:
      id:
        type: "integer"
        format: "int64"
      asset_upload_id:
        type: "integer"
        format: "int64"
      status:
        type: "string"
      description:
        type: "string"
      created_date:
        type: "string"
        format: "date-time"
      message:
        type: "object"
  AssetStatusUpdate:
    type: "object"
    properties:
      filename:
        type: "string"
      status:
        type: "string"
      description:
        type: "string"
      message:
        type: "object"
      timestamp:
        type: "string"
  AssetFinalUpdate:
    type: "object"
    properties:
      filename:
        type: "string"
      status:
        type: "string"
      description:
        type: "string"
      message:
        type: "object"
      timestamp:
        type: "string"
      final_assets:
        type: "array"
        items:
          type: "object"