swagger: "2.0"

info:
  version: 1.0.0
  title: API Specifications

schemes:
  - https
host: qa-ows-product-digital-marketing.theorchard.io
paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK
          examples:
            application/json: { "status": "ok" }
  /marketing/{product_id}:
    get:
      summary: Fetch product marketing highlight.
      parameters:
        - in: path
          name: product_id
          required: true
          type: string
        - description: Grass account type.
          enum:
            - vendor
            - subaccount
          in: header
          name: Grass-Account-Type
          required: false
          type: string
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          pattern: ^\d+$
          required: false
          type: string
        - description: Orchard-User-Id of OA/ALW user
          in: header
          name: Orchard-User-Id
          required: false
          type: string
      responses:
        200:
          description: 200 OK
          examples:
            application/json:
              highlight: "General drivers"
              apple_highlight: "apple drivers"
              spotify_highlight: "spotify drivers"
              apple_total: 5443
              spotify_total: null
              downloads_total: 10000
              projections:
                - id: 123
                  product_id: 1234
                  territory_id: 12345
                  spotify_projection: 100
                  apple_projection: 200
                  downloads_projection: 300
                  highlight: blub blub blub
                  priority: A
                - id: 223
                  product_id: 2234
                  territory_id: 22345
                  spotify_projection: 101
                  apple_projection: 201
                  downloads_projection: 301
                  highlight: beep beep beep
                  priority: B
        403:
          description: 403 User is forbidden
        404:
          description: 404 Highlight not found
    post:
      summary: Upsert product marketing highlight.
      parameters:
        - in: path
          name: product_id
          required: true
          type: string
        - in: body
          name: body
          required: true
          schema:
            $ref: '#/definitions/PostMarketingHighlight'
        - description: Grass account type.
          enum:
            - vendor
            - subaccount
          in: header
          name: Grass-Account-Type
          required: false
          type: string
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          pattern: ^\d+$
          required: false
          type: string
        - description: Orchard-User-Id of OA/ALW user
          in: header
          name: Orchard-User-Id
          required: false
          type: string
      responses:
        200:
          description: 200 OK
          examples:
            application/json:
              highlight: "General drivers"
              apple_highlight: "apple drivers"
              spotify_highlight: "spotify drivers"
              apple_total: 5443
              spotify_total: null
              downloads_total: 10000
        403:
          description: 403 User is forbidden
        404:
          description: 404 Highlight not found
  /marketing/{product_id}/projections:
    post:
      summary: Create product marketing highlight_projections.
      parameters:
        - in: path
          name: product_id
          required: true
          type: string
        - in: header
          description: Grass account type.
          enum:
            - vendor
            - subaccount
          name: Grass-Account-Type
          required: false
          type: string
        - in: header
          description: Grass account id.
          name: Grass-Account-Id
          pattern: ^\d+$
          required: false
          type: string
        - in: header
          description: Orchard-User-Id of OA/ALW user
          name: Orchard-User-Id
          required: false
          type: string
        - in: body
          name: items
          schema:
            type: array
            minItems: 1
            items:
              $ref: '#/definitions/CreateMarketingHighlightProjections'

      responses:
        201:
          description: 201 OK
          examples:
            application/json:
              {
                "items": [
                  {
                    "id": 123,
                    "territory_id": 213,
                    "spotify_projection": 500,
                    "apple_projection": null,
                    "downloads_projection": 300,
                    "highlight": "general marketing drivers",
                    "priority": "A",
                  },
                  {
                    "id": 124,
                    "territory_id": 214,
                    "spotify_projection": null,
                    "apple_projection": 300,
                    "downloads_projection": 200,
                    "highlight": "",
                    "priority": null,
                  },
                ]
              }
        403:
          description: 403 User is forbidden
        404:
          description: 404 Product Highlight not found
        500:
          description: A database error occured.
          examples:
            application/json:
              {
                "code": "internal_error",
                "message": "db error"
              }
  /marketing/territories:
   get:
     summary: Fetch product marketing territories.
     parameters:
       - description: Grass account type.
         enum:
           - vendor
           - subaccount
         in: header
         name: Grass-Account-Type
         required: false
         type: string
       - description: Grass account id.
         in: header
         name: Grass-Account-Id
         pattern: ^\d+$
         required: false
         type: string
       - description: Orchard-User-Id of OA/ALW user
         in: header
         name: Orchard-User-Id
         required: false
         type: string
     responses:
       200:
         description: 200 OK
         examples:
           application/json:
            items:
              - id: 0
                name: Lego Island
                category: continent
       403:
         description: 403 User is forbidden
       404:
         description: 404 Highlight not found
  /public/marketing/territories:
    get:
      summary: Fetch product marketing territories.
      responses:
        200:
          description: 200 OK
          examples:
            application/json:
             items:
               - id: 0
                 name: Lego Island
                 category: continent
        404:
          description: 404 Highlight not found
  /marketing/{product_id}/projection/{projection_id}:
    delete:
      summary: Delete projection for product.
      parameters:
        - in: path
          name: product_id
          required: true
          type: string
        - description: Grass account type.
          enum:
            - vendor
            - subaccount
          in: header
          name: Grass-Account-Type
          required: false
          type: string
        - description: Grass account id.
          in: header
          name: Grass-Account-Id
          pattern: ^\d+$
          required: false
          type: string
        - description: Orchard-User-Id of OA/ALW user
          in: header
          name: Orchard-User-Id
          required: false
          type: string
      responses:
        200:
          description: 200 OK
        403:
          description: 403 User is forbidden
        404:
          description: 404 Highlight projection not found
  /marketing/{source_product_id}/copy/{target_product_id}:
    post:
      summary: Copy marketing data from a source product to a target product
      parameters:
        - in: path
          name: source_product_id
          required: true
          type: string
        - in: path
          name: target_product_id
          required: true
          type: string
      responses:
        201:
          description: 201 OK
        400:
          description: 400 Target product already has a marketing highlight
        404:
         description: 404 Source Highlight not found
definitions:
  PostMarketingHighlight:
    type: object
    properties:
      global_highlight:
        type: string
      spotify_highlight:
        type: string
      apple_highlight:
        type: string
      spotify_total:
        type: integer
      apple_total:
        type: integer
      downloads_total:
        type: integer
  CreateMarketingHighlightProjections:
    type: object
    required:
      - territory_id
    properties:
      territory_id:
        type: number
        description: "Primary key of the territory"
      spotify_projection:
        type: number
        description: "Value of the Spotify streams projection"
      apple_projection:
        type: number
        description: "Value of the Apple streams projection"
      downloads_projection:
        type: number
        description: "Value of the downloads projection"
      highlight:
        type: string
        description: "marketing highlight for territory"
