swagger: "2.0"

info:
  version: 1.0.0
  title: Digital Product Workflow API

schemes:
  - https
host: qa-ows-product-workflow.theorchard.io
paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK
          examples:
            application/json: { "status": "ok" }
  /release-approval/{releaseApprovalId}/rejections:
    get:
      summary: Get the rejection details for the given release approval queue.
      parameters:
        - description: Primary key of a release approval queue.
          in: path
          name: releaseApprovalId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
      responses:
        200:
          description: Dictionary representation of the rejections.
          examples:
            default:
              items:
                - rejection_id: 0
                  comments: Smell the glove
                  table_name: releases
                  field_name: artwork
                  corrected: N
                  key_id: 0
        404:
          description: Could not find rejections for the given id release approval queue.
  /release-approval/rejections:
    put:
      summary: Update properties for a set of rejections.
      parameters:
        - $ref: '#/parameters/correlationId'
        - in: body
          name: body
          description: |
            The fields to update.
            example:
            ```json
              rejections [
                {
                  "rejection_id": "0",
                  "comments": "Smell the glove",
                  "table_name": "releases",
                  "field_name": "artwork",
                  "corrected": "Y",
                  "key_id": "0"
                }
              ]
            ```
          schema:
            type: object
            properties:
              rejection_id:
                type: integer
                description: The id of the rejection.
              comments:
                type: string
                description: Rejection comments.
              table_name:
                type: string
                description: rejection table name
              field_name:
                type: string
                description: rejection field name
              corrected:
                type: string
                description: if the rejection is corrected or not (Y, N)
              key_id:
                type: integer
                description: rejection key id for tracks
            required:
            - rejection_id
            - comments
            - table_name
            - field_name
            - corrected
            - key_id
      responses:
        200:
          description: An object representing the updated rejections.
          examples:
            default:
              items:
                - rejection_id: 0
                  comments: Smell the glove
                  table_name: releases
                  field_name: artwork
                  corrected: N
                  key_id: 0
  /product/{productId}/release-approval:
    get:
      summary: Get the latest release approval queue for a given product.
      parameters:
        - description: Primary key of a product.
          in: path
          name: productId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
      responses:
        200:
          description: Dictionary representation of the given product's latest release approval queue.
          examples:
            default:
              release_approval_id: 1
              release_correction_id: None
              status: rejected
              release_id: 123
    post:
      summary: Create a release approval queue for a given product.
      parameters:
        - description: Primary key of a product.
          in: path
          name: productId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
        - description: last updated by user id
          in: body
          name: release approval queue
          schema:
            type: object
            required:
              - status
              - admin_approval
            properties:
              status:
                type: string
              admin_approval:
                type: string
      responses:
        201:
          description: Dictionary representation of the created release approval queue.
          examples:
              default:
                release_approval_id: 1
                release_correction_id: None
                status: rejected
                release_id: 123
  /product/{productId}/submission:
    post:
      summary: Product submission workflow.
      parameters:
        - description: Primary key of a product.
          in: path
          name: productId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
        - in: body
          name: body
          description: Submit product parameters
          schema:
            type: object
            properties:
              error_correction_flag:
                type: boolean
              account_type:
                type: string
                nullable: true
              account_id:
                type: string
                nullable: true
              identity_id:
                type: string
                nullable: true
      responses:
        200:
          description: Dictionary representation of submission details.
          examples:
            default:
              latest_correction:
                release_correction_id: 42
                release_id: 123
                status: submitted
                items:
                  - release_correction_detail_id: 123
                    table_name: releases
                    field_name: primary
                    key_id: 2020202
                    key_value:
                      - artist_name: Emerald Park
                        role: primary
                  - release_correction_detail_id: 189
                    table_name: track
                    field_name: track
                    key_id: 123456
                    key_value: true
              release_approval:
                release_approval_id: 1
                release_correction_id: None
                status: rejected
                release_id: 123
  /product/{productId}/correction:
    get:
      summary: Get the latest release correction for a given product.
      parameters:
        - description: Primary key of a product.
          in: path
          name: productId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
      responses:
        200:
          description: Dictionary representation of the given product's latest release correction.
          examples:
            default:
              release_correction_id: 123,
              status: active
              items:
                - release_correction_detail_id: 123
                  table_name: releases
                  field_name: primary
                  key_id: 2020202
                  key_value:
                    - artist_name: Emerald Park
                      role: primary
                - release_correction_detail_id: 189
                  table_name: track
                  field_name: track
                  key_id: 123456
                  key_value: true
    post:
      summary: Create a release correction for a given product.
      parameters:
        - description: Primary key of a product.
          in: path
          name: productId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
        - description: last updated by user id
          in: body
          name: correction
          schema:
            type: object
            required:
              - lastUpdatedBy
              - lastUpdatedType
            properties:
              lastUpdatedBy:
                type: string
              lastUpdatedType:
                type: string
      responses:
        201:
          description: Dictionary representation of the created release correction.
          examples:
            default:
              release_correction_id: 123,
              status: active
              items:
                - release_correction_detail_id: 123
                  table_name: releases
                  field_name: primary
                  key_id: 2020202
                  key_value:
                    - artist_name: Emerald Park
                      role: primary
                - release_correction_detail_id: 189
                  table_name: track
                  field_name: track
                  key_id: 123456
                  key_value: true
  /correction/{releaseCorrectionId}/details:
    post:
      summary: Create the correction details for the given id and details.
      parameters:
        - description: Primary key of a release correction.
          in: path
          name: releaseCorrectionId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
        - in: body
          name: items
          description: Correction details payload
          schema:
            type: array
            items:
              type: object
              required:
                - table_name
                - field_name
                - key_id
                - key_value
                - last_updated
                - last_updated_by
                - last_updated_type
              properties:
                table_name:
                  type: string
                field_name:
                  type: string
                key_id:
                  type: integer
                key_value:
                  type: string
                last_updated:
                  type: string
                last_updated_by:
                  type: integer
                last_updated_type:
                  type: string
      responses:
        200:
          description: A list of dictionaries. Each dictionary represents newly created correction detail.
          examples:
            default:
              items:
                - release_correction_detail_id: 123
                  table_name: releases
                  field_name: primary
                  key_id: 2020202
                  key_value:
                    - artist_name: Emerald Park
                      role: primary
                - release_correction_detail_id: 189
                  table_name: track
                  field_name: track
                  key_id: 123456
                  key_value: true
  /correction/{releaseCorrectionId}:
    get:
      summary: Get the release correction for a given id.
      parameters:
        - description: Primary key of a release correction.
          in: path
          name: releaseCorrectionId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
      responses:
        200:
          description: Dictionary representation of the given release correction.
          examples:
            default:
              release_correction_id: 123,
              status: active
              items:
                - release_correction_detail_id: 123
                  table_name: releases
                  field_name: primary
                  key_id: 2020202
                  key_value:
                    - artist_name: Paranoid London
                      role: primary
                - release_correction_detail_id: 189
                  table_name: track
                  field_name: track
                  key_id: 123456
                  key_value: true
        404:
          description: Could not find the release correction for a given id.
    put:
      summary: Update properties for a release correction.
      parameters:
        - description: Primary key of a correction.
          in: path
          name: releaseCorrectionId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
        - in: body
          name: body
          description: |
            The fields to update.
            example:
            ```json
              {
                "status": "submitted"
                "last_updated_type": "vendor",
                "last_updated_by": "123",
              }
            ```
          schema:
            type: object
            properties:
              status:
                type: string
                description: The correction status.
              last_updated_type:
                type: string
                description: Last updated account type.
              last_updated_by:
                type: object
                description: 'Last updated accound it'
            required:
            - status
            - last_updated_type
            - last_updated_by
      responses:
        200:
          description: An object representing the updated correction detail.
          examples:
            default:
              body:
                - release_correction_id: 123
                  status: submitted
                  last_updated_type: vendor
                  last_updated_by: 13425
    delete:
      summary: Deletes the correction for the given id.
      parameters:
        - description: Primary key of a correction.
          in: path
          name: releaseCorrectionId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
      responses:
        202:
          description: A message confirming that the correction was deleted.
          examples:
            default:
              message: release correction deleted
  /product/{productId}/unsubmit:
    post:
      summary: Delete the latest release approval queue for a given product and reset its correction to active if present.
      parameters:
        - description: Primary key of a product.
          in: path
          name: productId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
        - in: body
          name: body
          description: Submit product parameters
          schema:
            type: object
            required:
              - account_type
              - account_id
            properties:
              error_correction_flag:
                type: boolean
              account_type:
                type: string
              account_id:
                type: string
      responses:
        200:
          description: A message confirming that the release approval queue was deleted.
          examples:
            default:
              message: release approval deleted
        400:
          description: An error message indicating that the product can not be unsubmitted.
          examples:
            default:
              message: Product 123 is not checked in
  /product/{productId}/metadata_queue:
    post:
      summary: Creates an update record in the meta_update_queue table for all previously delivered to stores.
      parameters:
        - description: Primary key of a product.
          in: path
          name: productId
          required: true
          type: string
        - $ref: '#/parameters/correlationId'
        - in: body
          name: body
          description: Additional data for creating a meta_update_queue record
          schema:
            type: object
            properties:
              delivery_store_ids:
                type: array
                items: 
                  type: integer
              description:
                type: string
                required: true
      response:
        201:
          description: A message confirming that a meta_update_queue record was created.
          examples:
            default:
              message: Meta Update Queue created successfully
        400:
          description: An error message indicating that a meta_update_queue record could not be created.
          examples:
            default:
              message: Requested product id 123 not found.
        404:
          description: An error message indicating that the product has not been delivered to any stores previously.
          examples:
            default:
              message: Product with 8799878232 was not delivered to any of the stores previously.
parameters:
  correlationId:
    in: header
    name: Correlation-Id
    required: false
    type: string