openapi: 3.0.0
info:
  version: 1.0.0
  title: ows-abacus-legacy-sync API Specifications
servers:
  - url: 'https://qa-ows-abacus-legacy-sync.theorchard.io'
    description: QA server
paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK

  /vendor-contract/:
    post:
      summary: Creates a new vendor contract
      requestBody:
        description: The vendor contract details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VendorContractPostBody'
      responses:
        '201':
          description: 200 OK
        '400':
          description: Bad data received in payload
        '401':
          description: 401 API key is missing or invalid

  /vendor-contract-distribution-type/:
    post:
      summary: Creates a new vendor_contract_distribution_type
      requestBody:
        description: The vendor_contract_distribution_type details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VendorContractDistributionTypePostBody'
      responses:
        '201':
          description: 201 CREATED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VendorContractDistributionTypeDetail'
        '400':
          description: Bad data received in payload
        '401':
          description: 401 API key is missing or invalid

  /vendor-contract-distribution-types/:
    post:
      summary: Bulk creates new vendor_contract_distribution_types
      requestBody:
        description: List of the vendor_contract_distribution_type details within an items key
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VendorContractDistributionTypesPostBody'
      responses:
        '201':
          description: 201 CREATED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/VendorContractDistributionTypesDetail'
        '400':
          description: Bad data received in payload
        '401':
          description: 401 API key is missing or invalid

  /vendor-contract/<int:vendor_contract_id:
    put:
      summary: Updates existing vendor contract
      requestBody:
        description: The vendor contract details that need to be updated
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/VendorContractPutBody'
      responses:
        '200':
          description: 200 OK
        '400':
          description: Bad data received in payload
        '401':
          description: 401 API key is missing or invalid

components:
  securitySchemes:
    Orchard-Identity-Id:
      type: apiKey
      in: header
      name: Orchard-Identity-Id

  schemas:
    VendorContractPostBody:
      title: Vendor Contract post body
      type: object
      properties:
        vendor_id:
          type: integer
          description: The Vendor ID
        cont_start':
          type: string
          description: Contract start date
        cont_end:
          type: string
          description: Contract end date
        contract_type:
          type: string
          description: Type of contract
        release_term:
          type: integer
          description: Number of years for the contract if the contract type is per_release_term
        opt_out:
          type: string
          description: Yes or No indicates whether or not deliver content to stores
        is_automatic_rollover:
          type: string
          description: Where to rollover automatically
        payment_interval:
          type: string
          description: How often the payment is due
        pay_after:
          type: string
          description: Days before payment is due
        digital_split:
          type: number
          description: Digital split between label and Orchard
        currency_code:
          type: number
          description: ISO code of the contract's currency
        country_exclusion:
          type: array
          items:
            type: string
          description: Countries that are restricted from the contract
      required:
        - vendor_id
        - cont_start
        - cont_end
        - currency_code
      example:
        vendor_id: 77
        cont_start: "2022-01-01"
        cont_end: "2122-12-31"
        contract_type: "vendor_term"
        release_term': 0
        opt_out': "N"
        is_automatic_rollover': "Y"
        payment_interval': "month"
        pay_after': 30
        digital_split': 0.75
        currency_code': "USD"
        country_exclusion': ["USA"]

    VendorContractDistributionTypePostBody:
      title: Vendor Contract Distribution Type POST request body
      type: object
      properties:
        vendor_contract_id:
          type: integer
          description: ID of related vendor_contract
        distribution_type_id:
          type: integer
          description: ID of related distribution_type
        new_store_default:
          type: string
          description: either 'Y' or 'N'.
                       Here 'N' implies that when a new store is added, distribution will be carried out automatically for the new store.

    VendorContractDistributionTypesPostBody:
      title: Vendor Contract Distribution Types POST request body
      type: object
      properties:
        items:
          type: array
          items:
            $ref: '#/components/schemas/VendorContractDistributionTypePostBody'
      required:
        - items
      example:
        items:
          - vendor_contract_id: 1
            distribution_type_id: 1
          - vendor_contract_id: 1
            distribution_type_id: 2

    VendorContractDistributionTypeDetail:
      title: Vendor Contract Distribution Type Details
      type: object
      allOf:
        - $ref: '#/components/schemas/VendorContractDistributionTypePostBody'
        - type: object
          properties:
            vendor_contract_distribution_type_id:
              type: integer
              description: ID of vendor_contract_distribution_type
      required:
        - vendor_contract_distribution_type
        - vendor_contract_id
        - distribution_type_id
        - new_store_default
      example:
        vendor_contract_distribution_type: 1
        vendor_contract_id: 1
        distribution_type_id: 1
        new_store_default: 'N'

    VendorContractDistributionTypesDetail:
      title: Vendor Contract Distribution Types Details
      type: object
      allOf:
        - $ref: '#/components/schemas/VendorContractDistributionTypesPostBody'
      required:
        - items
      example:
        items:
          - vendor_contract_distribution_type: 1
            vendor_contract_id: 1
            distribution_type_id: 1
            new_store_default: 'N'
          - vendor_contract_distribution_type: 2
            vendor_contract_id: 1
            distribution_type_id: 2
            new_store_default: 'N'

    VendorContractPutBody:
      title: Vendor Contract PUT body
      type: object
      properties:
        country_exclusion:
          type: array
          items:
            type: string
          description: Countries that are restricted from the contract
        store_exclusion:
          type: array
          items:
            type: string
          description: Stores that are restricted from the contract
        distribution_type_id:
          type: integer
          description: ID of related distribution_type
      example:
        country_exclusion': ["USA"]
        store_exclusion': ["1", "2"]
        distribution_type_id: 1
