openapi: 3.0.3
info:
  title: cx-data-services-lambda-loyalty
  description: Existing loyalty operations endpoints documentation
  version: v2
  contact:
    email: sedataops@carlsberg.com
    name: DataOps Team
servers:
  - url: https://api-eu.carlsbergwebservices.com/data/dev/v2
    description: Loyalty lambda API server url
  - url: https://api-eu.carlsbergwebservices.com/data/tst/v2
    description: Loyalty lambda API server url
  - url: https://api-eu.carlsbergwebservices.com/data/stg/v2
    description: Loyalty lambda API server url
  - url: https://api-eu.carlsbergwebservices.com/data/prd/v2
    description: Loyalty lambda API server url
tags:
  - name: loyalty
    description: Loyalty lambda endpoints
paths:
  /hello:
    get:
      tags:
        - loyalty
      operationId: fetchHello
      summary: Get hello
      description: Endpoint to see if service is alive
      responses:
        '200':
          $ref: '#/components/responses/LoyaltyHello'
  /{sales_org}/loyalty/{record_id}:
    get:
      tags:
        - loyalty
      operationId: fetchLoyalty
      summary: Get price by record id
      description: Concatenation of 2 fields and the proper format (customer_id + "_" + reference_id)
      responses:
        '200':
          $ref: '#/components/responses/Loyalty'
        '400':
          $ref: '#/components/responses/LoyaltyError'
    parameters:
      - $ref: '#/components/parameters/sales_org'
      - $ref: '#/components/parameters/record_id'
  /{sales_org}/loyalty:
    get:
      tags:
        - loyalty
      operationId: fetchAllLoyalty
      summary: Get loyalty by sales org
      description: Retrieve a list of loyalty for a specific sales org
      responses:
        '200':
          $ref: '#/components/responses/LoyaltyList'
        '400':
          $ref: '#/components/responses/LoyaltyError'
      parameters:
        - $ref: '#/components/parameters/fields'
        - $ref: '#/components/parameters/list'
        - $ref: '#/components/parameters/size'
        - $ref: '#/components/parameters/token'
    parameters:
      - $ref: '#/components/parameters/sales_org'
components:
  schemas:
    HelloModel:
      title: hello response
      x-stoplight:
        id: uirvwymi5hewn
      description: This is the response structure when testing availability
      type: object
      properties:
        message:
          description: Content of greeting test message
          type: string
          example: Hello from CxDataOps Data Services !!!
    LoyaltyModel:
      title: Loyalty schema
      x-stoplight:
        id: 5a61ef09ace49
      description: Body response of a price schema existing in DynamoBD
      type: object
      properties:
        timezone:
          description: Time Zone Content
          type: string
          example: UTC+1
        expiration_date:
          description: Expiration Date
          type: string
          example: '2030-02-19T23:00:00.00Z'
        reference_id:
          description: Event ID Content
          type: string
          example: ABC_1234567
        sales_org_code:
          description: Sales org code
          type: string
          example: X001
        value:
          description: Points Content
          type: string
          example: '-1000'
        customer_id:
          description: Customer ID
          type: string
          example: XYZ_987654
        availability_date:
          description: Date from point are available
          type: string
          example: '2024-02-19T23:00:00.00Z'
        account_type:
          description: Account Type
          type: string
          example: POINTS
        reason:
          description: Reason Description
          type: string
          example: Point Migration
    LoyaltyListModel:
      type: object
      x-stoplight:
        id: 176d82658fbab
      description: Body response of a loyalty list schema existing in DynamoBD
      properties:
        content:
          type: array
          description: Body response of a price schema existing in DynamoBD
          items:
            $ref: '#/components/schemas/LoyaltyModel'
          example:
            - $ref: '#/components/schemas/LoyaltyModel'
        pagination:
          $ref: '#/components/schemas/TokenPaginationModel'
    ErrorResponseModel:
      title: error response
      x-stoplight:
        id: c1d45af9abc32
      description: This is a schema for response when there is an error
      type: object
      properties:
        title:
          description: Title of the failure
          type: string
          example: Bad Request
        status:
          description: Error type code form response
          type: integer
          format: int32
          example: 400
        detail:
          description: More detailed information about the error
          type: string
          example: 'record_id: XYZ, sales_org: 9999 not found'
    TokenPaginationModel:
      title: Token Pagination
      x-stoplight:
        id: bjlk2cqbe9wq2
      type: object
      description: Pagination metadata for using token page method
      properties:
        size:
          type: integer
          format: int32
          description: The size (number of elements) displayed per page
          example: 100
        token:
          type: string
          description: Token used to fetch next page data
          example: '%7B%27sortkey%27%3A+%271010%27%2C+%27env%27%3A+%27dev%27%2C+%27partkey%27%3A+%RECORD_ID_dev%27%7D'
      example:
        size: 100
        token: '%7B%27sortkey%27%3A+%271010%27%2C+%27env%27%3A+%27dev%27%2C+%27partkey%27%3A+%RECORD_ID_dev%27%7D'
  parameters:
    sales_org:
      name: sales_org
      in: path
      schema:
        type: string
      required: true
      description: Sales Organization Code
      example: '9999'
    record_id:
      name: record_id
      in: path
      required: true
      schema:
        type: string
      description: Concatenation of 2 fields and the proper format (customer_id + "_" + reference_id)
      example: 999999999_XYZ_999999999_ABC
    size:
      name: size
      in: query
      required: false
      schema:
        type: integer
        format: int32
      description: Number of items to return
      example: 100
    fields:
      name: fields
      in: query
      required: false
      schema:
        type: string
      description: List of attributes from the body
      example: fields=sales_org_code
    token:
      name: token
      in: query
      required: false
      schema:
        type: string
      description: Token that retrieves next page of results
      example: '%7B%27sortkey%27%3A+%271010%27%2C+%27env%27%3A+%27dev%27%2C+%27partkey%27%3A+%RECORD_ID_dev%27%7D'
    list:
      name: list
      in: query
      required: false
      schema:
        type: string
      description: List of partkeys (without "_<env>"). Limit of 100 elements.
      example: list=999999999_XYZ_999999999_ABC, 111111111_ABC_111111111_XYZ
  responses:
    LoyaltyHello:
      description: Retrieve a static message just to verify deployment
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/HelloModel'
    Loyalty:
      description: Get price detail based in given record id and sales org
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LoyaltyModel'
    LoyaltyList:
      description: Get loyalty detail list based in given from sales org
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/LoyaltyListModel'
    LoyaltyError:
      description: Bad request model detailing the error
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponseModel'
x-stoplight:
  id: b1c5f23880cb1
