---
swagger: "2.0"

info:
  version: 1.0.0
  title: API Specifications

schemes:
  - https

definitions:
  DeliveryStore:
    type: object
    properties:
      id:
        type: number
        example: 286
      name:
        type: string
        example: "Spotify"
  FollowedEntity:
    type: string
    enum: &FollowedEntity
      - 'participant'
      - 'sound_recording'
      - 'vendor'
      - 'sub_account'
      - 'channel'
      - 'collaborator'
  Notification:
    type: object
    properties:
      actor:
        type: string
      verb:
        type: string
      object:
        type: string
      target:
        type: string
      time:
        type: number
      custom_field_1:
        type: string
      custom_field_2:
        type: number
      custom_field_3:
        type: object
  Product:
    type: object
    properties:
      id:
        type: number
        example: 2958087
      name:
        type: string
        example: "Vanishing Point"
      upc:
        type: string
        example: "195497264421"
  Subscription:
    type: object
    properties:
      notification_type:
        type: string
      feed_type:
        type: string
      app_id:
        type: string
      name:
        type: string
  UserSubscription:
    type: object
    properties:
      notification_type:
        type: string
      feed_type:
        type: string
      app_id:
        type: string
      name:
        type: string
      followAllResources:
        type: boolean
      followResources:
        type: array
        items:
          type: object
          properties:
            uuid:
              type: string
            name:
              type: string
            labels:
              type: array
              items:
                type: string
  TenantType:
    type: string
    enum: &TenantType
      - 'account'
      - 'subaccount'
      - 'label_participant'
      - 'collaborator'


host: qa-ows-notifications.theorchard.io
paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK
          examples:
            application/json: {"status": "ok"}
  /activity:
    post:
      summary: Add an activity to a feed
      parameters:
        - in: body
          name: data
          schema:
            type: object
            required:
              - feed_name
              - feed_id
              - payload
            properties:
              feed_name:
                type: string
              feed_id:
                type: string
              payload:
                type: object
      responses:
        201:
          description: 201 Created
        400:
          description: 400 Bad Parameters
        401:
          description: 401 Unauthorized
        404:
          description: 404 Not Found
        500:
          description: 500 Internal server error
  /subscribe:
    post:
      summary: Subscribe a user to a feed
      parameters:
        - in: header
          name: Orchard-User-Id
          type: string
        - in: header
          name: Grass-Account-Id
          type: number
        - in: body
          name: data
          schema:
            type: object
            required:
              - user_feed_name
              - feed_name
            properties:
              user_feed_name:
                type: string
              feed_name:
                type: string
              feed_id:
                type: string
              user_feed_id:
                type: string
      responses:
        200:
          description: 200 OK
        400:
          description: 400 Bad Parameters
        401:
          description: 401 Unauthorized
        404:
          description: 404 Not Found
        500:
          description: 500 Internal server error
  /unsubscribe:
    post:
      summary: Unsubscribe a user from a feed
      parameters:
        - in: header
          name: Orchard-User-Id
          type: string
        - in: header
          name: Grass-Account-Id
          type: number
        - in: body
          name: data
          schema:
            type: object
            required:
              - user_feed_name
              - feed_name
            properties:
              user_feed_name:
                type: string
              feed_name:
                type: string
              feed_id:
                type: string
              user_feed_id:
                type: string
      responses:
        200:
          description: 200 OK
        400:
          description: 400 Bad Parameters
        401:
          description: 401 Unauthorized
        404:
          description: 404 Not Found
        500:
          description: 500 Internal server error
  /user/notifications:
    get:
      summary: Get a user's notifications
      parameters:
        - in: header
          name: Orchard-User-Id
          type: string
          required: true
        - in: query
          name: user_feed_name
          type: string
          required: false
        - in: query
          name: user_feed_id
          type: string
          required: false
      responses:
        200:
          description: 200 OK
          schema:
            type: object
            properties:
              items:
                type: array
                items:
                  $ref: "#/definitions/Notification"
        400:
          description: 400 Bad Parameters
        401:
          description: 401 Unauthorized
        404:
          description: 404 Not Found
        500:
          description: 500 Internal server error
  /user/subscriptions:
    get:
      summary: Get a user's subscriptions
      parameters:
        - in: header
          name: Orchard-User-Id
          type: string
          required: true
        - in: query
          name: user_feed_name
          type: string
          required: false
        - in: query
          name: user_feed_id
          type: string
          required: false
      responses:
        200:
          description: 200 OK
          schema:
            type: object
            properties:
              items:
                type: array
                items:
                  type: string
        400:
          description: 400 Bad Parameters
        401:
          description: 401 Unauthorized
        404:
          description: 404 Not Found
        500:
          description: 500 Internal server error
  /feed/subscribers:
    get:
      summary: Get a feed's subscribers
      parameters:
        - in: query
          name: feed_name
          type: string
          required: true
        - in: query
          name: feed_id
          type: string
          required: true
      responses:
        200:
          description: 200 OK
          schema:
            type: object
            properties:
              items:
                type: array
                items:
                  type: string
        400:
          description: 400 Bad Parameters
        401:
          description: 401 Unauthorized
        404:
          description: 404 Not Found
        500:
          description: 500 Internal server error
  /subscription/{entity_type}:
    post:
      summary: Create specified relationship between Profile and Entity
      parameters:
        - name: Orchard-Profile-Type
          in: header
          type: string
        - name: Orchard-Profile-Id
          in: header
          type: string
        - name: entity_type
          in: path
          type: string
          enum: *FollowedEntity
          required: true
        - in: body
          name: body
          schema:
            additionalProperties: false
            properties:
              relationship:
                type: string
                description: The type of relationship
                example: HAS_FOLLOWED
              id:
                type: string
                description: The id of the entity node.
                example: 8028987d-3992-4836-866e-3be494f7d44a
              automatic:
                type: boolean
                description: If relationship was created via automatic process
                default: false
            required:
              - type
              - id
            type: object
      responses:
        201:
          description: 201 Created
        200:
          description: 200 Relationship already exists
        400:
          description: 400 Bad Request
  /subscription/{entity_type}/{entity_id}/relationship/{relationship}:
    get:
      summary: Check if specified relationship exists between Profile and Entity
      parameters:
        - name: Orchard-Profile-Type
          in: header
          type: string
        - name: Orchard-Profile-Id
          in: header
          type: string
        - name: entity_type
          in: path
          type: string
          enum: *FollowedEntity
          required: true
        - name: entity_id
          in: path
          type: string
          required: true
        - name: relationship
          in: path
          type: string
          required: true
          description: HAS_FOLLOWED, etc
      responses:
        200:
          description: 200 OK, the relationship exists
        404:
          description: 404 Relationship not found
        400:
          description: 400 Bad Parameters
    delete:
      summary: Soft delete the specified relationship between Profile and Entity
      parameters:
        - name: Orchard-Profile-Type
          in: header
          type: string
        - name: Orchard-Profile-Id
          in: header
          type: string
        - name: entity_type
          in: path
          type: string
          enum: *FollowedEntity
          required: true
        - name: entity_id
          in: path
          type: string
          required: true
        - name: relationship
          in: path
          type: string
          required: true
          description: HAS_FOLLOWED, etc
      responses:
        204:
          description: 204 No content, relationship soft deleted
        200:
          description: 200 Relationship did not exist, no action taken
        400:
          description: 400 Bad Parameters
  /subscription/{entity_type}/relationship/{relationship}:
    get:
      summary: List all Entities for a Profile with given relationship type
      parameters:
        - name: Orchard-Profile-Type
          in: header
          type: string
        - name: Orchard-Profile-Id
          in: header
          type: string
        - name: entity_type
          in: path
          type: string
          enum: *FollowedEntity
          required: true
        - name: relationship
          in: path
          type: string
          required: true
          description: HAS_FOLLOWED, etc
        - name: ids
          in: query
          type: string
          required: false
          description: comma separated list of entity_ids to match (max 50)
        - name: offset
          in: query
          type: integer
          required: false
          description: index to fetch items from
          default: 0
        - name: limit
          in: query
          type: integer
          required: false
          description: number of items to fetch
          default: all
        - name: order_by
          in: query
          type: string
          enum: [last_modified]
          required: false
          description: attribute to order results by
          default: last_modified
        - name: order_dir
          in: query
          type: string
          enum: [desc, asc]
          required: false
          description: direction to order results by
          default: desc
        - name: state
          in: query
          type: string
          enum: [all, undeleted, deleted]
          required: false
          description: deleted state to fetch items for
          default: undeleted
      responses:
        200:
          description: 200 Array of Entity nodes (can be empty array)
  /profile/{profile_id}/{profile_type}/subscriptions:
    get:
      summary: Get all active subscriptions for a given profile.
      parameters:
        - name: profile_id
          in: path
          type: string
          required: true
        - name: profile_type
          in: path
          type: string
          required: true
      responses:
        200:
          description: 200 OK
          schema:
            type: object
            properties:
              items:
                type: array
                items:
                  $ref: "#/definitions/Subscription"
        400:
          description: 400 Bad Parameters
        401:
          description: 401 Unauthorized
        404:
          description: 404 Not Found
        500:
          description: 500 Internal server error

  /subscriptions/all:
    get:
      summary: Get all subscriptions that are there in the system.
      parameters:
        - name: app_id
          in: query
          type: string
          required: false
        - name: notification_type
          in: query
          type: string
          required: false
      responses:
        200:
          description: 200 OK
          schema:
            type: object
            properties:
              items:
                type: array
                items:
                  $ref: "#/definitions/Subscription"
        401:
          description: 401 Unauthorized
        500:
          description: 500 Internal server error

  /identity/{identity_id}/subscriptions:
    get:
      summary: Get all subscriptions that are there in the system.
      parameters:
        - name: identity_id
          in: path
          type: string
          required: true
        - name: app_id
          in: query
          type: string
          required: false
        - name: notification_type
          in: query
          type: string
          required: false
      responses:
        200:
          description: 200 OK
          schema:
            type: object
            properties:
              items:
                type: array
                items:
                  $ref: "#/definitions/UserSubscription"
        401:
          description: 401 Unauthorized
        500:
          description: 500 Internal server error

  /identity/{identity_id}/report/participant-data:
    post:
      summary: Send email, user has reported an issue with participant data
      parameters:
        - name: identity_id
          in: path
          type: string
          required: true
        - name: body
          in: body
          schema:
            additionalProperties: false
            properties:
              application:
                type: object
                properties:
                  name:
                    type: string
                    example: orchard-go
                  version:
                    type: string
                    example: 2.0.1
              category:
                type: string
                example: DATA_INACCURATE
              message:
                type: string
                example: Phoebe Bridgers should have more followers.
              participant:
                type: object
                properties:
                  id:
                    type: string
                    example: 700cb3c2-fe8c-42eb-b1e0-dd376be6c15c
                  name:
                    type: string
                    example: Phoebe Bridgers
                  chartmetric_id:
                    type: string
                    example: 122237
              referrer:
                type: string
                description: The type of relationship
                example: PARTICIPANT_SCREEN
            required:
              - type
              - id
            type: object
      responses:
        202:
          description: 202 Message recorded successfully
        500:
          description: 500 Problem recording message
  /identity/{identity_id}/report/sound-recording-data:
    post:
      summary: Send email, user has reported an issue with sound recording data
      parameters:
        - name: identity_id
          in: path
          type: string
          required: true
        - name: body
          in: body
          schema:
            additionalProperties: false
            properties:
              application:
                type: object
                properties:
                  name:
                    type: string
                    example: orchard-go
                  version:
                    type: string
                    example: 2.0.1
              category:
                type: string
                example: DATA_INACCURATE
              message:
                type: string
                example: Phoebe Bridgers should have more streams.
              sound_recording:
                type: object
                properties:
                  isrc:
                    type: string
                    example: USJ5G2020003
                  name:
                    type: string
                    example: Kyoto
              artist_name:
                type: string
                description: Name of artist associated with sound recording
                example: Phoebe Bridgers
              referrer:
                type: string
                description: Referring screen/url
                example: PARTICIPANT_SCREEN
            required:
              - type
              - id
            type: object
      responses:
        202:
          description: 202 Message recorded successfully
        500:
          description: 500 Problem recording message
  /participant/activity/social_spike:
    post:
      summary: Add social spike event
      parameters:
        - name: body
          in: body
          schema:
            properties:
              date:
                type: string
                description: ISO formatted date of event
                example: "2019-06-15"
              network:
                type: string
                enum: [twitter, youtube, instagram]
                description: Social network data source of event
              new_followers:
                type: integer
                description: Number of new followers since previous day
              chartmetric_id:
                type: integer
                description: Unique ID of participant
      responses:
        201:
          description: Event recorded
        409:
          description: Event already recorded
  /sound_recording/activity/trending_track:
    post:
      summary: Add trending track event
      parameters:
        - name: body
          in: body
          schema:
            properties:
              date:
                type: string
                description: ISO formatted date of spike
                example: "2020-06-15"
              region:
                type: string
                description: Country spike occured in
              dsp:
                type: string
                enum: [spotify, itunes/apple]
                description: Streaming platform where spike happened
              percent_diff:
                type: integer
                description: Percent difference streams increase from day before date
                example: 150
              day_streams:
                type: integer
                description: Number of streams on date
                example: 10000
              track:
                type: object
                properties:
                  id:
                    type: integer
                    description: Internal unique ID of track
                  isrc:
                    type: string
                    description: Unique ID of sound recording
                  vendor_id:
                    type: integer
                    description: Internal unique ID of vendor owning track
                  subaccount_id:
                    type: integer
                    description: Internal unique ID of subaccount owning track
      responses:
        200:
          description: No subscribers, event received
        201:
          description: Event received, some or all subscribers updated
        409:
          description: Event already received
  /sound_recording/activity/playlist_placement:
    post:
      summary: Add playlist placement event
      parameters:
        - name: body
          in: body
          schema:
            properties:
              timestamp:
                type: string
                description: ISO formatted date and time of event
                example: "2020-06-15 12:05:00"
              playlist:
                type: object
                properties:
                  dsp:
                    type: string
                    enum: [spotify, itunes/apple]
                    description: Streaming platform where playlist exists
                  store_id:
                    type: integer
                    description: Internal identifier for the DSP
                  rank:
                    type: integer
                    description: Importance of playlist (ordering TBD)
                    example: 100
                  id:
                    type: string
                    description: Unique identifier of playlist, from DSP
                    example: "37i9dQZF1DX6ziVCJnEm59"
                  name:
                    type: string
                    description: Human readable name of playlist
                    example: "Collection of Songs, Volume #1"
              sound_recording:
                type: object
                properties:
                  isrc:
                    type: string
                    description: Unique ID of sound recording
                  vendor_id:
                    type: integer
                    description: Internal ID of vendor owning recording
                  subaccount_id:
                    type: integer
                    description: Internal ID of subaccount owning recording
      responses:
        200:
          description: No subscribers, event received
        201:
          description: Event received, some or all subscribers updated
        409:
          description: Event already received
  /permissions/updated:
    post:
      summary: Notify a user that their permissions have been updated.
      parameters:
        - name: body
          in: body
          schema:
            properties:
              identity_id:
                type: string
                format: uuid
                description: Identity Id of the user.
                required: true
              tenant_type:
                $ref: "#/definitions/TenantType"
                required: true
              tenant_uuid:
                type: string
                format: uuid
                description: The UUID of the tenant.
                required: true
              brand:
                type: string
                description: The brand name associated with the tenant.
                required: true
      responses:
        204:
          description: Email sent successfully
        404:
          description: Identity not found
  /distribution/scheduled_update_failed:
    post:
      summary: Send an email notifying that a scheduled metadata update failed.
      tags: ['Distribution']
      parameters:
        - name: body
          in: body
          schema:
            properties:
              product:
                $ref: "#/definitions/Product"
              recipients:
                type: array
                items:
                  type: string
                example: ['bburton@sonymusic-pde.com', 'lseal@sonymusic-pde.com']
              delivery_stores:
                type: array
                items:
                  $ref: "#/definitions/DeliveryStore"
              update:
                type: object
                properties:
                  sale_start_date:
                    type: string
                    example: "2023-05-20"
      responses:
        202:
          description: Email sent successfully
  /distribution/ws_scheduled_update_failed:
    post:
      summary: Send an email notifying that a ws scheduled metadata update failed.
      tags: ['Distribution']
      parameters:
        - name: body
          in: body
          schema:
            properties:
              product:
                $ref: "#/definitions/Product"
              recipients:
                type: array
                items:
                  type: string
                example: ['bburton@sonymusic-pde.com', 'lseal@sonymusic-pde.com']
      responses:
        202:
          description: Email sent successfully
  /distribution/ws_scheduled_update_processed:
    post:
      summary: Send an email notifying that a ws scheduled metadata update processed.
      tags: ['Distribution']
      parameters:
        - name: body
          in: body
          schema:
            properties:
              product:
                $ref: "#/definitions/Product"
              recipients:
                type: array
                items:
                  type: string
                example: ['bburton@sonymusic-pde.com', 'lseal@sonymusic-pde.com']
      responses:
        202:
          description: Email sent successfully
  /audience/shopify-store-sync-completed:
    post:
      summary: Email the user that their Shopify store sync has been completed.
      tags: ['Audience']
      parameters:
        - name: body
          in: body
          schema:
            properties:
              identity_id:
                type: string
                description: Identity Id of the user to notify.
              store_id:
                type: string
                description: Audience Shopify Store Id.
              store_domain:
                type: string
                description: Shopify Store domain.
              is_multiartist_store:
                type: boolean
                description: Whether the Shopify store contains products of multiple Artists.
      responses:
        204:
          description: Email sent successfully
        404:
          description: Identity not found
  /audience/audience-file-exported:
    post:
      summary: Email the user that their audience file has been exported.
      tags: ['Audience']
      parameters:
        - name: body
          in: body
          schema:
            properties:
              identity_id:
                type: string
                description: Identity Id of the user to notify.
              audience_name:
                type: string
                description: Exported audience name.
              filename:
                type: string
                description: Export file name.
              password:
                type: string
                description: Exported file password to un-archive it.
            required:
              - identity_id
              - audience_name
              - filename
              - password
      responses:
        204:
          description: Email sent successfully
        404:
          description: Identity not found
