swagger: "2.0"

info:
  version: 1.0.0
  title: API Specifications

schemes:
  - https
host: qa-ows-blacklist-manager.theorchard.io
paths:
  /:
    get:
      summary: Hello World path.
      responses:
        200:
          description: 200 OK
          examples:
            text/html: "Hello Bill!"
  /{username}:
    get:
      summary: Hello World with an optional GET param "username".
      parameters:
        - in: path
          name: username
          required: true
          type: string
      responses:
        200:
          description: 200 OK
          examples:
            text/html: "Hello Bill!"
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK
          examples:
            application/json: { "status": "ok" }
  /blacklist-reason/:
    post:
      summary: Create a new blacklist reason.
      parameters:
        - description: UUID
          in: header
          name: Correlation-Id
          type: string
          required: false
        - description: Grass account type.
          in: header
          name: Grass-Account-Type
          type: string
          enum:
            - vendor
            - subaccount
          required: false
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          type: integer
          required: false
        - in: body
          name: body
          schema:
            $ref: '#/definitions/blacklist-reason-post-body'
      responses:
        201:
          description: 201 Created
          examples:
            default:
              id: 1
        400:
          description: 400 Bad Parameters
        500:
          description: 500 Internal server error
  /blacklist-reasons/:
    get:
      summary: Get all the blacklist reason.
      parameters:
        - description: UUID
          in: header
          name: Correlation-Id
          type: string
          required: false
        - description: Grass account type.
          in: header
          name: Grass-Account-Type
          type: string
          enum:
            - vendor
            - subaccount
          required: false
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          type: integer
          required: false
      responses:
        200:
          description: 200 Success
          examples:
            default:
              - id: 1,
                reason: 'Valid Reason for blacklisting'
                added_by: 562
                alert: 1234
                contact: 'any@gmail.com'
                date_added: '2018-02-02'
                date_updated: '2019-02-02'
              - id: 2,
                reason: 'Valid Reason for blacklisting 2'
                added_by: 563
                alert: 12345
                contact: 'any1@gmail.com'
                date_added: '2018-02-03'
                date_updated: '2019-02-03'
        400:
          description: 400 Bad Parameters
        500:
          description: 500 Internal server error
  /blacklist-words/:
    get:
      summary: Get all the blacklist words.
      parameters:
        - description: UUID
          in: header
          name: Correlation-Id
          type: string
          required: false
        - description: Grass account type.
          in: header
          name: Grass-Account-Type
          type: string
          enum:
            - vendor
            - subaccount
          required: false
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          type: integer
          required: false
        - description: Offset for pagination.
          in: query
          name: page_offset
          type: string
          pattern: ^\d+$
          required: false
        - description: Max number of results per page.
          in: query
          name: page_limit
          type: string
          pattern: ^[1-9]\d*$
          required: false
        - description: Blacklist term to match. e.g. 'Blacklisted'
          in: query
          name: q
          type: string
          required: false
      responses:
        200:
          description: 200 Success
          examples:
            default:
              items:
                - id: 1
                  word: 'Blacklisted Word1'
                  notes: 'notes for word'
                  blacklist_reason:
                    - id: 1
                    - reason: 'Valid Reason'
                  added_by:
                    - id: 1
                    - name: 'Test User'
                  date_added: '2019-02-02'
                - id: 2
                  word: 'Blacklisted Word2'
                  notes: 'notes for word'
                  blacklist_reason:
                    - id: 2
                    - reason: 'Valid Reason'
                  added_by:
                    - id: 2
                    - name: 'Test User'
                  date_added: '2018-02-03'
              pagination:
                type: standard
                offset: 0
                limit: 3
                count: 2
        400:
          description: 400 Bad Parameters
        500:
          description: 500 Internal server error
  /blacklist-words/{blacklist_id}:
    delete:
      summary: Delete blacklist word.
      parameters:
        - in: path
          name: blacklist_id
          required: true
          type: integer
        - description: UUID
          in: header
          name: Correlation-Id
          type: string
          required: false
        - description: Grass account type.
          in: header
          name: Grass-Account-Type
          type: string
          enum:
            - vendor
            - subaccount
          required: false
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          type: integer
          required: false
      responses:
        200:
          description: 200 OK
        404:
          description: 404 Not found
          examples:
            application/json: {
                "code": "not_found_error",
                "message": "Blacklist Id not found"
            }
        500:
          description: 500 Internal server error
          examples:
            application/json: {
                "code": "server_error",
                "message": "Could not connect to Mysql Database"
            }
    put:
      summary: Update blacklist word.
      parameters:
        - description: Id of the blacklist word to be updated
          in: path
          name: blacklist_id
          required: true
          type: integer
        - description: UUID
          in: header
          name: Correlation-Id
          type: string
          required: false
        - description: Grass account type.
          in: header
          name: Grass-Account-Type
          type: string
          enum:
            - vendor
            - subaccount
          required: false
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          type: integer
          required: false
        - in: body
          name: body
          schema:
            $ref: '#/definitions/blacklist-put-word-body'
      responses:
        200:
          description: 200 OK
          examples:
            application/json: {
                "id": 1
            }
        404:
          description: 404 Not found
          examples:
            application/json: {
                "code": "not_found_error",
                "message": "Blacklist Id not found"
            }
        500:
          description: 500 Internal server error
          examples:
            application/json: {
                "code": "server_error",
                "message": "Could not connect to Mysql Database"
            }

  /blacklist-word/:
    post:
      summary: Create a new blacklist word.
      parameters:
        - description: UUID
          in: header
          name: Correlation-Id
          type: string
          required: false
        - description: Grass account type.
          in: header
          name: Grass-Account-Type
          type: string
          enum:
            - vendor
            - subaccount
          required: false
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          type: integer
          required: false
        - in: body
          name: body
          schema:
            $ref: '#/definitions/blacklist-post-word-body'
      responses:
        201:
          description: 201 Created
          examples:
            default:
              id: 1
        500:
          description: 500 Internal server error
  /validate/{productId}:
    get:
      summary: Validate if release data contains blacklisted word.
      parameters:
        - description: unique id of product
          in: path
          name: productId
          type: integer
          required: true
        - description: UUID
          in: header
          name: Correlation-Id
          type: string
          required: false
        - description: Grass account type.
          in: header
          name: Grass-Account-Type
          type: string
          enum:
            - vendor
            - subaccount
          required: false
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          type: integer
          required: false
      responses:
        200:
          description: 200 Success
          examples:
            Blacklist word not found in product:
              message: non_blacklisted
            Blacklist word found in product:
              message: blacklisted
        400:
          description: 400 Bad Parameters
          examples:
            application/json:
              validation_error:
                matched_blacklist_words:
                  - 6ix9ine
                  - 88GLAM
                items:
                  - word: 6ix9ine
                    reason: Store-Blocked Artist
                    alert: One or more stores have blocked delivery of content by this Artist. A one-sheet and confirmation of master rights is required for approval and delivery.
                    contact: qc@theorchard.com
                    matched_field: track_artist_names
                  - word: 6ix9ine
                    reason: Store-Blocked Artist
                    alert: One or more stores have blocked delivery of content by this Artist. A one-sheet and confirmation of master rights is required for approval and delivery.
                    contact: qc@theorchard.com
                    matched_field: artist_names
                  - word: 88GLAM
                    reason: Store-Blocked Artist
                    alert: One or more stores have blocked delivery of content by this Artist. A one-sheet and confirmation of master rights is required for approval and delivery.
                    contact: qc@theorchard.com
                    matched_field: track_artist_names

        404:
          description: 404 Product not found
        500:
          description: 500 Internal server error

  /validate-text:
    post:
      summary: Validate if text contains a blacklisted word.
      parameters:
        - in: body
          name: body
          schema:
              $ref: '#/definitions/blacklist-validate-text-post-body'
      responses:
        200:
          description: 200 no blacklist words found
        400:
          description: 400 input validation failed or blacklist words found
        404:
          description: 404 Product not found
        500:
          description: 500 Internal server error

  /validate-artists:
    post:
      summary: Validate if artist data contains a blacklisted word.
      parameters:
        - in: body
          name: body
          schema:
            $ref: '#/definitions/blacklist-validate-artists-post-body'
      responses:
        200:
          description: 200 no blacklisted artists found
        400:
          description: 400 blacklisted artists found
          examples:
            application/json:
              product_id: 123
              validation_errors:
                track_artists:
                  - tuid: 10
                    matches:
                      - name: BadArtist
                        role: main
                        reason: Store-Blocked Artist
                product_artists:
                  matches:
                    - name: BadArtist
                      role: feature
                      reason: Store-Blocked Artist
        500:
          description: 500 Internal server error

  /blacklist-reasons/{blacklist_id}:
    put:
      summary: Update blacklist reason.
      parameters:
        - description: Id of the blacklist reason to be updated
          in: path
          name: blacklist_id
          required: true
          type: integer
        - description: UUID
          in: header
          name: Correlation-Id
          type: string
          required: false
        - description: Grass account type.
          in: header
          name: Grass-Account-Type
          type: string
          enum:
            - vendor
            - subaccount
          required: false
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          type: integer
          required: false
        - in: body
          name: body
          schema:
            $ref: '#/definitions/blacklist-reason-put-body'
      responses:
        200:
          description: 200 OK
          examples:
            application/json: {
                "id": 1
            }
        404:
          description: 404 Not found
          examples:
            application/json: {
                "code": "not_found_error",
                "message": "Blacklist Id not found"
            }
        500:
          description: 500 Internal server error
          examples:
            application/json: {
                "code": "server_error",
                "message": "Could not connect to Mysql Database"
            }

definitions:
  blacklist-reason-post-body:
    additionalProperties: false
    properties:
      reason:
        description: Reason for which a word is blacklisted.
        type: string
      added_by:
        description: Logged in user who added blacklist word.
        type: integer
      alert:
        description: Alert message for the blacklisted reason.
        type: string
      contact:
        description: Email address to contact for blacklisted reason.
        type: string
    required:
      - added_by
    type: object

  blacklist-post-word-body:
    additionalProperties: false
    properties:
      word:
        description: Some blacklisted word.
        type: string
      notes:
        description: Some notes for given blacklisted word.
        type: string
      blacklist_reason_id:
        description: Id of the blacklisted reason.
        type: integer
      added_by:
        description: added by id (eg:-562).
        type: integer
    required:
      - added_by
      - blacklist_reason_id
      - word
    type: object

  blacklist-put-word-body:
      additionalProperties: false
      properties:
        word:
          description: Some blacklisted word.
          type: string
        notes:
          description: Some notes for given blacklisted word.
          type: string
        blacklist_reason_id:
          description: Id of the blacklisted reason.
          type: integer
      type: object

  blacklist-reason-put-body:
      additionalProperties: false
      properties:
        reason:
          description: Some blacklisted reason.
          type: string
      type: object

  blacklist-validate-text-post-body:
    additionalProperties: false
    properties:
      text:
        description: Text to be checked for blacklisting.
        type: string
    type: object
  blacklist-validate-artists-post-body:
    additionalProperties: false
    properties:
      product_id:
        description: Product id.
        type: integer
      track_artists:
        description: Track artists grouped by track to be checked for blacklisting.
        type: array
        items:
          type: object
          properties:
            tuid:
              description: Track unique identifier.
              type: integer
            artists:
              type: array
              items:
                type: object
                properties:
                  name:
                    description: Artist name.
                    type: string
      product_artists:
        description: Product-level artists to be checked for blacklisting.
        type: array
        items:
          type: object
          properties:
            name:
              description: Artist name.
              type: string
    type: object
