openapi: 3.0.0
info:
  version: 1.0.0
  title: ows-royalties API Specifications
servers:
  - url: 'https://qa-ows-royalties.theorchard.io'
    description: QA server

paths:
  /hello/:
    get:
      summary: Check the health of the application.
      responses:
        200:
          description: 200 OK

  /contracts/:
    get:
      summary: Return a paginated list of contracts
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ContractDetails'
                  total_count:
                    type: integer
                    example: 1
      parameters:
        - name: contract_name
          in: query
          required: false
          schema:
            type: string
          description: Get contracts by contract name
        - name: search_ter,
          in: query
          required: false
          schema:
            type: string
          description: search contracts by name and id
        - name: account_ids
          in: query
          required: false
          schema:
            type: string
          description: get contracts by account_ids
        - name: contract_type
          in: query
          required: false
          schema:
            type: string
          description: get contracts by contract type
        - name: is_excluded_from_accounting_run
          in: query
          required: false
          schema:
            type: boolean
          description: get contracts by is_excluded_from_accounting_run
        - name: contract_statuses
          in: query
          required: false
          schema:
            type: string
          description: get contracts by one or more contract lifecycle status(comma separated values)
    post:
      summary: GET contracts by a list of contract_ids. Uses POST to allow for a larger list of query args.
      requestBody:
        description: List of contract_ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [10]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractDetails'

  /contracts/dataloader/:
    post:
      summary: Get a list of contracts by contract_ids
      requestBody:
        description: List of contract_ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractsDataloaderResponse'

  /contracts/snapshot/:
    get:
      summary: Return a csv of contracts
      parameters:
        - description: List of contract IDs
          name: contract_ids
          in: query
          style: form
          explode: false
          required: false
          schema:
            type: array
            items:
              type: integer
      responses:
        '200':
          description: 200 OK
          content:
            text/csv: {}

  /contracts/vat-info/:
    post:
      summary: GET contracts vat info by a list of contract_ids. Uses POST to allow for a larger list of query args.
      requestBody:
        description: List of contract_ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [10, 15]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractVatInfoDetail'

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

  /contract/{contract_id}/:
    get:
      summary: Retrieves contract details
      parameters:
        - description: The ID of the contract
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractDetails'
        '404':
          description: 404 NOT FOUND
    put:
      summary: Update contract details for a specified contract.
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: An object containing the contract fields that need to be updated.
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractPutBody'
      responses:
        '200':
          description: 200 ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractDetails'
        '404':
          description: 404 contract not found
    delete:
      summary: Delete a contract.
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  deleted:
                    type: boolean

  /contract/{contract_id}/terminate/:
    put:
      summary: Terminate a contract
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Termination details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractTerminationBody'
      responses:
        '200':
          description: Terminated
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractTermDetail'
        '400':
          description: Bad data received in payload

  /contract/{contract_id}/reactivate/:
    put:
      summary: Reactivate a contract
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractDetails'

  /contract/{contract_id}/can-be-deleted:
    get:
      summary: Check if a contract can be deleted
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  can_be_deleted:
                    type: boolean

  /contracts/account/{account_id}/:
    get:
      summary: Return array of contracts belonging to the specified account
      parameters:
        - description: The account ID
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractDetails'

  /contracts/account/dataloader/:
    post:
      summary: Get a list of contracts by account_ids
      requestBody:
        description: List of account_ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
      responses:
        '200':
          description: Success
          content:
              application/json:
                schema:
                  type: array
                  description: List of contracts
                  items:
                    $ref: '#/components/schemas/ContractDetails'
        '400':
          description: Bad data received in payload

  /contracts/accounts/:
    post:
      summary: Get contracts associated to the list of specified account ids. Uses POST to allow for a larger list of query args.
      requestBody:
        description: Array of account_ids
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractDetails'

  /contract/{contract_id}/contract-term/:
    post:
      summary: Create a contract term associated to the specified contract
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract term details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractTermPostBody'
      responses:
        '201':
          description: 201 Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractTermDetail'
        '404':
          description: 404 contract not found

  /contracts/{contract_id}/contract-terms/:
    get:
      summary: Get all contract terms associated to the specified contract
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractTermDetail'
        '404':
          description: 404 contract not found


  /contract-lifecycle-schedule-detail/{contract_lifecycle_schedule_detail_id}/:
    get:
      summary: Get contract lifecycle schedule detail by specified id
      parameters:
        - description: The contract lifecycle schedule detail id
          name: contract_lifecycle_schedule_detail_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractLifecycleScheduleDetailResponse'
        '404':
          description: 404 contract lifecycle schedule detail not found

  /contract-lifecycle-schedule-detail/dataloader/:
    post:
      summary: Get a list of contract lifecycle schedule details by contract_lifecycle_schedule_detail_ids
      requestBody:
        description: List of contract_lifecycle_schedule_detail_ids
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: integer
      responses:
        '200':
            description: 200 OK
            content:
              application/json:
                schema:
                  type: array
                  items:
                      $ref: '#/components/schemas/ContractLifecycleScheduleDetailDataloaderResponse'
        '400':
          description: Bad data received in payload

  /contracts/{contract_id}/contract-lifecycle-schedules/:
    get:
      summary: Get all contract lifecycle schedules associated to the specified contract
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleScheduleResponse'
        '400':
          description: contract doesn't exist

  /contract-lifecycle-schedule/{contract_lifecycle_schedule_id}/:
    get:
      summary: Get a contract lifecycle schedule by contract_lifecycle_schedule_id
      parameters:
        - description: The contract_lifecycle_schedule ID
          name: contract_lifecycle_schedule_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleScheduleResponse'
        '404':
          description: 404 ContractLifecycleSchedule not found

  /contract-lifecycle-schedules/dataloader/:
    post:
      summary: Dataload contract lifecycle schedules by ids
      requestBody:
        description: The contract_lifecycle_schedule ids
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractLifecycleScheduleIdsPostBody'
      responses:
        '200':
          description: Success
          content:
              application/json:
                schema:
                  type: array
                  description: List of ContractLifecycleSchedule details
                  items:
                    $ref: '#/components/schemas/DataloadedContractLifecycleScheduleList'
        '400':
          description: Bad data received in payload

  /contract-template/{contract_template_id}/contract/:
    post:
      summary: Create a contract from the specified contract template
      parameters:
        - description: ID of contract template
          name: contract_template_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: account details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/GDAContractPostBody'
      responses:
        '201':
          description: 201 Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GDAContractDetail'
        '404':
          description: 404 contract not found

  /contract-term/{contract_term_id}/:
    put:
      summary: Update attachments for a specified contract term.
      parameters:
        - description: The contract term ID
          name: contract_term_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: An array of attachments
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractTermPutBody'
      responses:
        '200':
          description: 200 ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractTermDetail'
        '404':
          description: 404 contract term not found
    get:
      summary: Get contract term by specified id
      parameters:
        - description: The contract term id
          name: contract_term_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractTermDetail'
        '404':
          description: 404 contract term not found
    delete:
      summary: Delete contract term and attached term conditions by specified contract_term_id
      parameters:
        - description: id of the contract term
          name: contract_term_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '204':
          description: success
        '400':
          description: contract_term does not exist or already deleted

  /contract-term/{contract_term_id}/conditions/:
    get:
      summary: Retrieves contract term conditions
      parameters:
        - description: The id of the contract
          name: contract_term_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractTermConditionDetail'
        '404':
          description: 404 NOT FOUND
    post:
      summary: Create one or more contract term conditions for the specified contract term
      parameters:
        - description: The contract term ID
          name: contract_term_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: An array of one or more contract term condition details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractTermConditionPostBody'
      responses:
        '201':
          description: 201 created
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractTermConditionDetail'
        '404':
          description: 404 contract term not found
    put:
      summary: Update one or more specified contract term conditions.
      parameters:
        - description: The contract term ID
          name: contract_term_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: An array of one or more contract term condition details
        required: true
        content:
          application/json:
            schema:
              allOf:
                - $ref: '#/components/schemas/ContractTermConditionDetail'
      responses:
        '200':
          description: 200 ok
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractTermConditionDetail'
        '404':
          description: 404 contract term not found || 404 contract term condition not found
        '400':
          description: contract term condition does not belong to contract term

  /account/{account_id}/contract-terms/:
    post:
      summary: GET contract-terms belonging to the specified account.
      parameters:
        - description: An Account ID
          name: account_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: An object of term_type and list of attachments
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractTermsAttachmentsPostBody'
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractTermDetail'
        '400':
          description: 400 invalid data in payload
        '404':
          description: 404 contract terms not found

  /contract-terms/snapshot/:
    get:
      summary: Return a csv of contract term
      parameters:
        - description: List of contract IDs
          name: contract_ids
          in: query
          style: form
          explode: false
          required: false
          schema:
            type: array
            items:
              type: integer
      responses:
        '200':
          description: 200 OK
          content:
            text/csv: {}

  /contract-term-conditions/soft-delete/:
    put:
      summary: Soft delete one or more contract term conditions
      requestBody:
        description: An array of contract_term_condition_ids
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                type: integer
                description: A list of contract_term_condition_ids
            example: [1, 2, 3]
      responses:
        '200':
          description: 200 ok
        '404':
          description: 404 contract term condition not found
        '400':
          description: contract term condition cannot be deleted

  /oa-contracts/contracts/:
    post:
      summary: GET contracts belonging to the specified orchard admin contracts. Uses POST to allow for a larger list of query args.
      requestBody:
        description: The list of oa_contract_ids
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractDetails'

  /contract/{contract_id}/reserves/:
    get:
      summary: Get reserve by contract id
      parameters:
        - description: The ID of contract
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                  $ref: '#/components/schemas/ContractReserveDetail'
    post:
      summary: Create a reserve associated to the specified contract
      parameters:
        - description: The ID of contract
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: contract reserve details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractReservePostBody'
      responses:
        '201':
          description: 201 Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractReserveDetail'
        '400':
          description: 400 invalid data in payload
    put:
      summary: Update a reserve associated to the specified contract, via soft-delete/insert
      parameters:
        - description: The ID of contract
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: contract reserve details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractReservePostBody'
      responses:
        '201':
          description: 201 Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractReserveDetail'
        '400':
          description: 400 invalid data in payload

  /contract/contract-reserves/:
    post:
      summary: GET reserves by list of contract_ids. Uses POST to allow for a larger list of query args.
      requestBody:
        description: List of contract_ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [10]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractReserveDetailWithAccountId'

  /contract-reserves/:
    post:
      summary: GET reserves by list of contract_reserve_ids. Uses POST to allow for a larger list of query args.
      requestBody:
        description: List of contract_reserve_ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [10]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractReserveDetail'

  /contract/{contract_id}/advances/{status}/:
    get:
      summary: Get a list of contract advances for a specified contract and status
      parameters:
        - in: path
          name: contract_id
          description: ID of the contract
          required: true
          schema:
            type: integer
        - in: path
          name: status
          description: Status of the advance is either pending, not_qualified, qualified, paid, in_review, approved or deleted
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      oneOf:
                        - $ref: '#/components/schemas/ContractAdvanceDetail'
                        - $ref: '#/components/schemas/ContractAdvancePaidDetail'
                  total_count:
                    type: integer
                    example: 1

  /contract/{contract_id}/advance/:
    post:
      summary: Create a new contract advance
      parameters:
        - in: path
          name: contract_id
          description: ID of the parent contract
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract advance details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractAdvancePostBody'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractAdvanceDetail'

  /contract-advance/{contract_advance_id}/:
    get:
      summary: Retrieves contract advance details
      parameters:
        - description: The ID of the contract advance
          name: contract_advance_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractAdvanceDetail'
        '404':
          description: 404 NOT FOUND
    put:
      summary: Update contract advance details
      parameters:
        - description: The ID of the contract advance
          name: contract_advance_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract advance details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractAdvancePutBody'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractAdvanceDetail'
        '404':
          description: 404 NOT FOUND
    delete:
      summary: Soft delete a Contract Advance
      parameters:
      - description: ID of the contract_advance
        name: contract_advance_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '204':
          description: success
        '400':
          description: contract_advance does not exist
        '404':
          description: contract_advance is already deleted or can not be deleted

  /reference-flowthrough-calculation/{reference_flowthrough_calculation_id}/:
    get:
      summary: GET a reference_flowthrough_calculation by ID
      description: Get a reference_flowthrough_calculation by reference_flowthrough_calculation_id
      parameters:
        - description: ID of the reference_flowthrough_calculation
          name: reference_flowthrough_calculation_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferenceFlowthroughCalculation'
        404:
          description: Not found

  /reference-flowthrough-calculations/:
      get:
        summary: GET list of reference flowthrough calculations
        description: GET list of reference flowthrough calculations
        responses:
          200:
            description: Success
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    items:
                      type: array
                      items:
                        $ref: '#/components/schemas/ReferenceFlowthroughCalculation'
                    total_count:
                      type: integer
                      example: 1

  /reference-sap-profit-center/:
    get:
      summary: GET list of SAP Profit Centers
      description: GET list of SAP Profit Centers ordered alphabetically by profit_center
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ReferenceSapProfitCenterDetail'
                  total_count:
                    type: integer
                    example: 1

  /reference-sap-profit-center/{reference_sap_profit_center_id}/:
    get:
      summary: GET an SAP Profit Center by ID
      description: Get SAP Profit Center by reference_sap_profit_center_id
      parameters:
        - description: The abacus ID of the SAP Profit Center
          name: reference_sap_profit_center_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferenceSapProfitCenterDetail'
        404:
          description: Not found

  /reference-payment-types/:
    get:
      summary: GET list of Payment Types
      description: GET list of Payment Types ordered by reference_payment_type_id
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ReferencePaymentTypeDetail'
                  total_count:
                    type: integer
                    example: 1

  /reference-payment-type/{reference_payment_type_id}/:
    get:
      summary: GET a Payment Type by ID
      description: GET a Payment Type by reference_payment_type_id
      parameters:
        - description: The abacus ID of the Payment Type
          name: reference_payment_type_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferencePaymentTypeDetail'
        404:
          description: Not found

  /contract-party/:
    post:
      summary: Creates a new contract_party with the specified details
      requestBody:
        description: contract party details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractPartyPostBody'
      responses:
        '201':
          description: 201 Created
        '400':
          description: Bad data received in payload

  /contract/{contract_id}/{target_type}/parties/:
    get:
      summary: Get a list of contract parties by contract_id and target_type
      parameters:
        - in: path
          name: contract_id
          description: id of the contract
          required: true
          schema:
            type: integer
        - in: path
          name: target_type
          description: must be one of 'contributor', 'label'
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                        $ref: '#/components/schemas/ContractPartyDetails'
                  total_count:
                    type: integer
                    example: 1
        '400':
          description: Bad Request

  /contract/{contract_id}/parties/:
    get:
      summary: Get a list of contract parties by contract_id
      parameters:
        - in: path
          name: contract_id
          description: id of the contract
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                        $ref: '#/components/schemas/ContractPartyDetails'
                  total_count:
                    type: integer
                    example: 1
        '400':
          description: Bad Request

  /contract-party/{contract_party_id}/:
    delete:
      summary: Soft delete a Contract Party
      parameters:
      - description: id of the contract_party
        name: contract_party_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '204':
          description: success
        '400':
          description: contract_party does not exist or is already deleted

  /contract-term/{contract_term_id}/contract-term-schedules/:
    get:
      summary: Get a list of contract term schedules by contract_term_id
      parameters:
        - in: path
          name: contract_term_id
          description: id of the contract_term
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractTermScheduleDetail'
        '404':
          description: 404 NOT FOUND
        '400':
          description: contract_term does not exist

  /reference-payment-entities/:
    get:
      summary: GET a list of reference payment entities
      description: GET a list of reference payment entities
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ReferencePaymentEntityDetail'
                  total_count:
                    type: integer
                    example: 1

  /reference-payment-entity/{reference_payment_entity_id}/:
    get:
      summary: GET a reference_payment_entity by ID
      description: Get a reference_payment_entity by reference_payment_entity_id
      parameters:
        - description: ID of the reference_payment_entity
          name: reference_payment_entity_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferencePaymentEntityDetail'
        404:
          description: Not found

  /reference-transaction-types/:
    get:
      summary: Get transaction types
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReferenceTransactionTypeDetail'

  /reference-transaction-type-groups:
    get:
      summary: Get a list of all transaction type groups
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReferenceTransactionTypeGroupDetail'

  /reference-transaction-type-group/group-admin/{group_admin}/:
    get:
      summary: Get list of transaction type groups by the group_admin
      description: Get list of reference_transaction_type_groups by the group_admin category
      parameters:
        - description: one of 'contract_admin', 'tax_admin', or 'workstation'
          name: group_admin
          in: path
          required: true
          schema:
            type: string
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReferenceTransactionTypeGroupDetail'
        404:
          description: invalid group_admin

  /reference-transaction-type-group/{reference_transaction_type_group_id}/reference-transaction-types/:
    get:
      summary: Get a list of transaction types by parent group
      description: Get a list of reference_transaction_type by reference_transaction_type_group_id
      parameters:
        - description: ID of the parent reference_transaction_type_group_id
          name: reference_transaction_type_group_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReferenceTransactionTypeDetail'
        404:
          description: reference_transaction_type_group_id does not exist

  /reference-transaction-type-group/reference_transaction_type_group_transaction_types:
    get:
      summary: Get a list of transaction type groups and their transaction_types
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ReferenceTransactionTypeGroupTransactionType'

  /contract/{contract_id}/contract-lifecycle/:
    get:
      summary: Get a contract lifecycle associated to the specified contract
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleDetail'
        '400':
          description: contract doesn't exist
    put:
      summary: Update a contract lifecycle associated to the specified contract
      parameters:
        - description: The contract ID
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: contract lifecycle details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractLifecyclePutBody'
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleDetail'
        '404':
          description: Contract doesn't exist
        '400':
          description: Lifecycle data required

  /contract/contract-lifecycle/dataloader/:
    post:
      summary: GET contracts by a list of contract_ids. Uses POST to allow for a larger list of query args.
      requestBody:
        description: List of contract_ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [10]
      responses:
        '200':
          description: Success
          content:
              application/json:
                schema:
                  type: array
                  description: List of ContractLifecycle details
                  items:
                    $ref: '#/components/schemas/DataloadedContractLifecycleList'
        '400':
          description: Bad data received in payload

  /contract-lifecycle-schedule/{contract_lifecycle_schedule_id}/contract-lifecycle/:
    get:
      summary: Get a contract lifecycle associated to the specified contract_lifecycle_schedule_id
      parameters:
        - description: The contract_lifecycle_schedule ID
          name: contract_lifecycle_schedule_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleDetail'
        '404':
          description: 404 ContractLifecycleSchedule not found

  /contract-lifecycle/{contract_lifecycle_id}/:
    get:
      summary: Get a contract lifecycle by contract_lifecycle_id
      parameters:
        - description: The contract_lifecycle ID
          name: contract_lifecycle_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleDetail'
        '404':
          description: 404 ContractLifecycle not found

  /contract-lifecycles/dataloader/:
    post:
      summary: Dataload contract lifecycles by ids
      requestBody:
        description: The contract_lifecycle ids
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractLifecycleIdsPostBody'
      responses:
        '200':
          description: Success
          content:
              application/json:
                schema:
                  type: array
                  description: List of ContractLifecycle details
                  items:
                    $ref: '#/components/schemas/DataloadedContractLifecycleList'
        '400':
          description: Bad data received in payload

  /contract-lifecycles/renewable/:
    get:
      summary: Get renewable contract_lifecycle records
      description: Get 'active' contract_lifecycle records with a renewal_effective date of today
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    description: total number of contract_lifecycle records ready to be renewed
                    example: 1
                    type: integer
                  items:
                    description: the contract_lifecycle records ready to be renewed
                    type: array
                    items:
                      $ref: '#/components/schemas/ContractLifecycleDetail'

  /contract-lifecycles/renew/:
    post:
      summary: Renewing contract_lifecycle records that are due for renewal.
      requestBody:
        description: List of contract_lifecycle ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [1, 2, 3]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleDetail'
        '404':
          description: 404 contract_lifecycle not found
        '400':
          description: Invalid lifecycle_status or renewal_effective date

  /contract-lifecycles/terminable/:
    get:
      summary: Get terminable contract_lifecycle records
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    description: total number of contract_lifecycle records that are to be terminated
                    example: 1
                    type: integer
                  items:
                    description: the contract_lifecycle records that are to be terminated
                    type: array
                    items:
                      $ref: '#/components/schemas/ContractLifecycleDetail'

  /contract-lifecycles/terminate/:
    post:
      summary: Update the lifecycle_status of contract_lifecycle records to either "terminated" or "in_collection_period"
      description: This endpoint will only "terminate" contract lifecycles that are in
                   "to_be_terminated" or "in_collection_period" state, and are due to be terminated by date.
      requestBody:
        description: List of contract_lifecycle ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [1, 2, 3]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleDetail'

  /contract-lifecycles/activable:
    get:
      summary: Get activable contract_lifecycle records
      description: Get contract_lifecycle records in the init state with a lifecycle_term_start date of today
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                type: object
                properties:
                  total_count:
                    description: total number of contract_lifecycle records ready to be activated
                    example: 1
                    type: integer
                  items:
                    description: the contract_lifecycle records ready to be activated
                    type: array
                    items:
                      $ref: '#/components/schemas/ContractLifecycleDetail'

  /contract-lifecycles/activate/:
    post:
      summary: Update the lifecycle_status of contract_lifecycle records to "active"
      description: This endpoint will only "activate" contract lifecycles that are in
        the "init" state.
      requestBody:
        description: List of contract_lifecycle ids.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                type: number
            example:
              [ 1, 2, 3 ]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractLifecycleDetail'

  /contract/{contract_id}/contract-lifecycle-schedules/:
    post:
      summary: Create one or two contract lifecycle schedules
      parameters:
        - in: path
          name: contract_id
          description: ID of the parent contract
          required: true
          schema:
            type: integer
        - name: allow_end_date_in_past
          in: query
          description: Allow schedule end date in the past. Used for backfilling contracts.
          required: false
          schema:
            type: boolean
      requestBody:
        description: The contract lifecycle schedule fields
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractLifecycleSchedulePostBody'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractLifecycleScheduleResponse'
        '400':
          description: Bad data received in payload
        '409':
          description: already exist
    put:
      summary: Updates one or two contract lifecycle schedules
      parameters:
        - in: path
          name: contract_id
          description: ID of the parent contract
          required: true
          schema:
            type: integer
        - in: query
          name: allow_end_date_in_past
          description: Allow schedule end date in the past. Used for backfilling contracts.
          required: false
          schema:
            type: boolean
      requestBody:
        description: The contract lifecycle schedule fields
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractLifecycleSchedulePutBody'
      responses:
        '200':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractLifecycleScheduleResponse'
        '400':
          description: Bad data received in payload

  /contract/{contract_id}/contract-lifecycle-schedule/{contract_lifecycle_schedule_id}/contract-lifecycle/:
    post:
      summary: Create a new contract lifecycle
      parameters:
        - in: path
          name: contract_id
          description: ID of the parent contract
          required: true
          schema:
            type: integer
        - in: path
          name: contract_lifecycle_schedule_id
          description: ID of the parent contract_lifecycle_schedule
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract contract_lifecycle_schedule details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractLifecyclePostBody'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractLifecycleDetail'
        '400':
          description: Bad data received in payload or contract/contract_lifecycle_schedule does not exist
        '409':
          description: already exist

  /contract/contract-lifecycle-schedule/contract-lifecycle/:
    post:
      summary: Creates a new contract with contract_lifecycle_schedules and contract_lifecycle
      requestBody:
        description: The contract, contract_lifecycle_schedule and contract_lifecycle details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractAndLifecyclePostBody'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractDetails'
        '400':
          description: Bad data received in payload or contract id already exists

  /reference-mechanical-rates/:
    get:
      summary: GET a list of reference mechanical rates
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/ReferenceMechanicalRateDetail'
                  total_count:
                    type: integer
                    example: 1

  /reference-mechanical-rate/{reference_mechanical_rate_id}/:
    get:
      summary: GET a reference_mechanical_rate by reference_mechanical_rate_id
      parameters:
        - description: ID of the reference_mechanical_rate
          name: reference_mechanical_rate_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ReferenceMechanicalRateDetail'
        404:
          description: reference_mechanical_rate Not found

  /contract-mechanical-deduction/{contract_mechanical_deduction_id}/:
    get:
      summary: GET a contract_mechanical_deduction by contract_mechanical_deduction_id
      parameters:
        - description: ID of the contract_mechanical_deduction
          name: contract_mechanical_deduction_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractMechanicalDeductionDetail'
        404:
          description: contract_mechanical_deduction Not found

  /contract/{contract_id}/contract-mechanical-deductions/:
    get:
      summary: GET list of contract mechanical deductions by contract_id
      parameters:
        - in: path
          name: contract_id
          description: ID of the parent contract
          required: true
          schema:
            type: integer
      responses:
        200:
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractMechanicalDeductionDetail'
        404:
            description: 404 Contract Mechanical Deduction not found

  /contracts/mechanical-deductions/active:
    get:
      summary: Get active contracts with mechanical deductions by date
      description: Returns contracts with active mechanical deductions filtered by date.
      parameters:
        - in: query
          name: date
          description: "Filter by active date (format: YYYY-MM-DD). Defaults to today."
          required: false
          schema:
            type: string
            format: date
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ActiveContractsByDate'
        '400':
          description: Invalid date format
        '401':
          description: Unauthorized

  /contract/{contract_id}/contract-mechanical-deductions/worldwide/:
    post:
      summary: Creating contract mechanical deductions worldwide i.e USA, CAN, ROW
      parameters:
        - in: path
          name: contract_id
          description: ID of the contract
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract_mechanical_deduction fields
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractWorldWideMechanicalDeductionPostBody'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractMechanicalDeductionDetail'
        '400':
          description: Bad data received in payload
        '404':
          description: Contract Not Found

  /contract/{contract_id}/contract-mechanical-deduction/:
    post:
      summary: Create a new contract_mechanical_deduction
      parameters:
        - in: path
          name: contract_id
          description: ID of the parent contract
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract_mechanical_deduction fields
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractMechanicalDeductionPostBody'
      responses:
        '201':
          description: Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractMechanicalDeductionDetail'
        '400':
          description: Bad data received in payload
        '404':
          description: Contract Not Found

  /contract-mechanical-deduction/{contract_mechanical_deduction_id}:
    put:
      summary: Update contract_mechanical_deduction data
      parameters:
        - in: path
          name: contract_mechanical_deduction_id
          description: ID of the contract_mechanical_deduction
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract_mechanical_deduction fields
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractMechanicalDeductionPutBody'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractMechanicalDeductionDetail'
        '400':
          description: Bad data received in payload
        '404':
          description: ContractMechanicalDeduction Not Found
    delete:
        summary: Soft delete a Contract Mechanical Deduction
        parameters:
          - description: ID of the contract_mechanical_deduction
            name: contract_mechanical_deduction_id
            in: path
            required: true
            schema:
              type: integer
        responses:
            '204':
              description: Success
            '404':
              description: contract_mechanical_deduction does not exist or is already deleted

  /contract-flowthrough/{contract_flowthrough_id}/:
    get:
      summary: Get a contract flowthrough by contract_flowthrough_id
      parameters:
        - description: ID of the contract_flowthrough
          name: contract_flowthrough_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractFlowthroughDetail'
        '404':
          description: ContractFlowthrough doesn't exist
    put:
      summary: Updates contract flowthrough
      parameters:
        - description: ID of the contract_flowthrough
          name: contract_flowthrough_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract flowthrough fields
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractFlowthroughPutBody'
      responses:
        '200':
          description: Ok
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractFlowthroughDetail'
        '400':
          description: Bad data received in payload
    delete:
      summary: Soft delete a Contract Flowthrough
      parameters:
        - description: ID of the contract_flowthrough
          name: contract_flowthrough_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '204':
          description: Success
        '404':
          description: contract_flowthrough does not exist or is already deleted

  /contract/{contract_id}/contract-flowthrough/:
    get:
      summary: Get a contract_flowthrough associated to the specified contract
      parameters:
        - description: ID of the contract
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ContractFlowthroughDetail'
        '404':
          description: contract doesn't exist
    post:
      summary: Create a contract flowthrough
      parameters:
        - description: ID of the contract
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: The contract flowthrough fields
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ContractFlowthroughPostBody'
      responses:
        '201':
          description: 201 Created
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ContractFlowthroughDetail'
        '400':
          description: Bad data received in payload
        '409':
          description: contract_flowthrough already exist
        '404':
          description: 404 contract not found

  /dag_run_time/{dag_id}:
    get:
      summary: Retrieves the run times for a particular DAG
      parameters:
        - description: The ID of the DAG
          name: dag_id
          in: path
          required: true
          schema:
            type: string
          example: 'accounting_run_calculate'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DagRunTimes'
        '500':
          description: Error getting DAG run times {error}

components:
  schemas:
    ContractAdvancePostBody:
      title: Contract advance post body
      type: object
      properties:
        advance_description:
          type: string
          description: description for the advance
        amount:
          type: number
          description: currency amount of the advance
        vat_amount:
          type: number
          description: VAT amount
        withholding_tax_amount:
          type: number
          description: Withholding tax amount, expected to be negative
        us_source_income_rate:
          type: number
          description: US source income %
        currency_code:
          type: string
          description: ISO currency code
        milestone:
          type: string
          description: One of 'contract_execution', 'delivery', 'recoupment', 'scheduled_installment', 'sales_milestone', 'other'
        milestone_description:
          type: string
          description: description text for the milestone
        milestone_date:
          type: string
          description: date for the milestone
        advance_status:
          type: string
          default: 'not_qualified'
          description: one of 'not_qualified', 'qualified', 'approved', 'paid', 'deleted'
        note:
          type: string
          description: extra notes to include for the advance
      required:
        - advance_description
        - amount
        - currency_code
        - milestone
        - milestone_description
        - milestone_date
      example:
        advance_description: 'testing one two three'
        amount: 100.00
        vat_amount: 20.00
        withholding_tax_amount: -20.00
        us_source_income_rate: 10.000001
        currency_code: 'GBP'
        milestone: 'contract_execution'
        milestone_description: 'words'
        advance_status: 'qualified'
        note: 'This is a pretty good example of a note.'

    ContractAdvancePutBody:
      title: Contract advance put body
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractAdvancePostBody'
        - type: object

    ContractPostBody:
      title: Contract post body
      type: object
      properties:
        account_id:
          type: integer
          description: The contract's account ID
        contract_id:
            type: integer
            description: The contract's ID (optional argument)
        contract_name:
          type: string
          description: The contract's name
        contract_type:
          type: string
          default: 'distribution'
          description: The type of contract being created
          enum:
            - distribution
            - legacy_distribution
            - neighbouring_rights
        oa_contract_id:
          type: integer
          description: ID of OA contract
        reference_signing_entity_id:
          type: integer
          description: ID of related reference_signing_entity
        summary_note:
          type: string
          description: Summary notes related to the contract
        general_note:
          type: string
          description: General notes related to the contract
        term_start:
          deprecated: true
          type: string
          description: The contract's term start date
        term_end:
          deprecated: true
          type: string
          description: The contract's term end date
        execution_date:
          description: date on which the contract was countersigned
          type: string
      required:
        - contract_name
        - contract_type
      example:
        account_id: 123
        contract_name: 'Best Contract'
        contract_type: 'distribution'
        oa_contract_id: 123
        reference_signing_entity_id: 1
        summary_note: 'Best Contract summary notes'
        general_note: 'Best Contract general notes'
        execution_date: '2020-01-01'

    ContractDetails:
      title: Contract Details
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractPostBody'
        - type: object
          properties:
            contract_id:
              description: ID of the contract
              type: integer
            sap_created_at:
              description: date contract data was sent to SAP
              type: string
            initial_start_date:
              description: date on which the contract is first activated
              type: string
            is_excluded_from_accounting_run:
              description: whether a contract should be used during the accounting run calculation(by default all contracts are included)
              type: boolean
      example:
        account_id: 12
        contract_id: 10
        contract_name: 'Best Contract'
        contract_type: 'distribution'
        oa_contract_id: 123
        reference_signing_entity_id: 1
        summary_note: 'Best Contract summary notes'
        general_note: 'Best Contract general notes'
        sap_created_at: '2022-06-01'
        initial_start_date: '2019-06-01'
        execution_date: None
        is_excluded_from_accounting_run: false

    ContractPutBody:
      title: Contract Put Body
      type: object
      properties:
        contract_name:
          type: string
          description: contract's name
        reference_signing_entity_id:
          type: integer
          description: ID of related reference_signing_entity
        sap_created_at:
          type: string
          description: date contract data was sent to SAP
        summary_note:
          type: string
          description: Summary notes related to the contract
        general_note:
          type: string
          description: General notes related to the contract
        term_start:
          deprecated: true
          type: string
          description: contract's term start date
        term_end:
          deprecated: true
          type: string
          description: contract's term end date
        is_excluded_from_accounting_run:
          description: whether a contract should be used during the accounting run calculation(by default all contracts are included)
          type: boolean
        execution_date:
          description: date on which the contract was countersigned
          type: string
        initial_start_date:
          description: date on which the contract is first activated
          type: string
      example:
        contract_name: 'Best Contract'
        reference_signing_entity_id: 1
        sap_created_at: '2019-06-01'
        summary_note: 'Best Contract summary notes'
        general_note: 'Best Contract general notes'
        is_excluded_from_accounting_run: 1
        execution_date: '2019-08-08'

    ContractTerminationBody:
      title: Terminate Contract Put Body
      type: object
      properties:
        termination_effective:
          type: string
          description: date contract is terminated
        termination_notice_received:
          type: string
          description: date notice of termination was received
      required:
        - termination_effective
      example:
        termination_effective: '2024-08-27'
        termination_notice_received: '2024-08-20'

    ContractTermPostBody:
      title: Contract Term post body
      type: object
      properties:
        contract_id:
          type: integer
          description: The ID of the parent contract
        contract_term_name:
          type: string
          description: Name of the contract term
        term_type:
          type: string
          description: The term type; one of 'label', 'product', 'artist', 'catalog', 'label', 'contributor_schedule', or 'contribution_schedule'
        attachments:
          type: array
          items:
            type: string
            description: Unique identifiers coinciding with the term_type
        schedule_ids:
          type: array
          items:
            type: string
            description: a list of schedule ids.
        attachments_relations:
          type: object
          properties:
            label_ids:
              type: array
              items:
                type: string
            upcs:
              type: array
              items:
                type: string
        is_base_term:
          type: boolean
          description: Whether or not the contract_term is the base term for the specified contract
      required:
        - contract_id
        - term_type
        - attachments
      example:
        contract_id: 456
        contract_term_name: 'Test contract term'
        term_type: product
        attachments: [10, 18]
        attachments_relations:
          label_ids: [12, 25]
          upcs: []
        is_base_term: true
        schedule_ids: ['1', '2']

    ContractTermDetail:
      title: Contract Term Detail
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractTermPostBody'
        - type: object
          properties:
            contract_term_id:
              type: integer
              description: The contract term's ID

    ContractTermPutBody:
      title: Contract Term put body
      type: object
      properties:
        attachments:
          type: array
          items:
            type: string
            description: Unique identifiers coinciding with the term_type
        attachments_relations:
          type: object
          properties:
            label_ids:
              type: array
              items:
                type: string
            upcs:
              type: array
              items:
                type: string
        contract_term_name:
          type: string
          description: Name of the contract term
                      (Updates only when existing contract type is 'contributor_schedule' or 'contribution_schedule')
        term_type:
          type: string
          description: The term type; one of 'label', 'product', 'artist', 'catalog', 'label', 'contributor_schedule', or 'contribution_schedule'
                      (Updates only when existing contract type is 'contributor_schedule' or 'contribution_schedule')
        schedule_ids:
          type: array
          items:
            type: string
            description: a list of schedule ids.
      required:
        - attachments
      example:
        contract_term_name: 'Test contract term'
        schedule_ids: ['1', '2']
        term_type: 'contributor_schedule'
        attachments: [10, 18]
        attachments_relations:
          label_ids: [12, 25]
          upcs: [12345, 54321]

    ContractTermConditionPostBody:
      title: Contract Term Condition post body
      type: object
      properties:
        contract_term_id:
          type: integer
          description: The ID of the parent contract term
        conditions:
          type: object
          properties:
            countries:
              type: array
              items:
                type: string
                description: A list of three-letter iso country codes for which the contract term should be applied
            stores:
              type: array
              items:
                type: string
                description: A list of store_ids for which the contract term should be applied
            transaction_types:
              type: array
              items:
                type: string
                description: A list of transaction_type_ids for which the contract term should be applied
        priority:
          type: integer
          minimum: 1
          description: Priority in which the contract_term_condition should be applied during an accounting run calculation. Defaults to 1.
        term_rate:
          type: number
          description: Percentage at which the term_rate should be applied to transactions (sales) meeting all the conditions of the contract
            (the sum of commission and term_rate should equal to 100)
        commission:
          type: number
          description: Percentage at which the commission should be applied to transactions (sales) meeting all the conditions of the contract
            (the sum of commission and term_rate should equal to 100)
        contract_term_condition_name:
          type: string
          description: Contract term condition name
      required:
        - contract_term_id,
        - term_rate
      example:
        contract_term_id: 123
        contract_term_condition_name: 'Condition name'
        conditions:
          - countries: ['MEX', 'USA']
          - stores: [22, 33]
          - transaction_types: []
        priority: 1
        term_rate: 20.20
        commission: 79.80

    ContractTermConditionDetail:
      title: Contract Term Condition Detail
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractTermConditionPostBody'
        - type: object
          properties:
            contract_term_condition_id:
              type: integer
              description: The contract term condition's ID
      example:
        contract_term_condition_id: 789
        contract_term_condition_name: 'Condition name'
        contract_term_id: 123
        conditions:
          - countries: ['MEX', 'USA']
          - stores: [22, 33]
          - transaction_types: []
        priority: 1
        term_rate: 20.20
        commission: 79.80

    ContractVatInfoDetail:
      title: Contract Vat Info Detail
      type: object
      properties:
        account_id:
          type: integer
          description: Account ID
        contract_id:
          type: integer
          description: Contract ID
        country_of_tax_residence:
          type: string
          description: Alpha-3 code of the country of tax residence
        account_is_sba_signed:
          type: boolean
          description: Is SBA signed
        client_tax_rate:
          type: number
          description: VAT Percentage for Client Accounts
        supplier_tax_rate:
          type: number
          description: VAT Percentage for Supplier Accounts
      example:
        account_id: 789
        contract_id: 123
        country_of_tax_residence: GBR
        account_is_sba_signed: true
        client_tax_rate: 20.00
        supplier_tax_rate: 20.00

    ContractExclusionPostBody:
      title: Contract Exclusion POST request body
      type: object
      properties:
        countries:
          type: array
          items:
            type: string
            description: List of country codes to be excluded from contract distribution
        stores:
          type: array
          items:
            type: string
            description: List of store_ids to be excluded from contract distribution
      example:
        countries: ['USA', 'CAN']
        stores: ['123', '456']

    ContractExclusionDetails:
      title: Contract Distribution Exclusion Details
      type: object
      properties:
        contract_exclusion_id:
          description: Id of contract exclusion
          type: integer
        contract_id:
          description: Id of contract
          type: integer
        exclusions:
          description: Country/territory and store/service exclusions
          type: object
          allOf:
            - $ref: '#/components/schemas/ContractExclusionPostBody'
      example:
        contract_exclusion_id: 1
        contract_id: 1
        exclusions:
          countries: ['USA', 'CAN']
          stores: ['123', '456']
    StoreDetail:
      title: Store (AKA "Service") Detail
      type: object
      properties:
        store_id:
          type: integer
          description: The ID of the store / service
        store_name:
          type: string
          description: The name of the store / service
      example:
        store_id: 1483
        store_name: Spotify US


    GDAContractPostBody:
      title: POST body for creating contract from template
      type: object
      properties:
        account_id:
          type: integer
          description: Id of an account
        account_name:
          type: string
          description: Name of an account
      example:
        account_id: 1
        account_name: 'Test Name'

    GDAContractDetail:
      title: Details of contract
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractDetails'
        - $ref: '#/components/schemas/ContractExclusion'
        - $ref: '#/components/schemas/ContractTermDetail'
        - type: object
          properties:
            run_controller_id:
              type: integer
              description: ID of run controller

    ContractTermsAttachmentsPostBody:
      title: POST body to get contract terms by attachments and term_type
      type: object
      properties:
        term_type:
          type: string
          description: The term type; one of 'label', 'product', 'artist', 'catalog', or 'label'
        attachments:
          type: array
          items:
            type: string
            description: Unique identifiers coinciding with the term_type
      example:
        term_type: product
        attachments: [10, 18]

    ContractReservePostBody:
      title: Contract Reserve POST body
      type: object
      properties:
        installments_in_months:
          type: number
          description: The number of months that reserves taken will be divided across; 1 - 24
        reserve_rate:
          type: number
          description: The percentage of reserves to be held
        reserve_release_offset_in_months:
          type: number
          description: The number of months from when reserves are taken that they begin to be released; 1 - 24
        release_schedule:
          type: array
          items:
            type: string
          description: List of splitted rates
      required:
        - installments_in_months
        - reserve_rate
        - reserve_release_offset_in_months
      example:
        installments_in_months: 2
        reserve_rate: 1.8
        reserve_release_offset_in_months: 1

    ContractReserveDetail:
      title: Contract Reserve Details
      type: object
      properties:
        contract_id:
          type: number
          description: The Id of the contract
        contract_reserve_id:
          type: number
          description: The Id of the contract-reserve
        installments_in_months:
          type: number
          description: The number of months that reserves taken will be divided across; 1 - 24
        reserve_rate:
          type: number
          description: The percentage of reserves to be held
        reserve_release_offset_in_months:
          type: number
          description: The number of months from when reserves are taken that they begin to be released; 1 - 24
        release_schedule:
          type: array
          items:
            type: string
          description: List of splitted rates
      example:
        contract_id: 1
        contract_reserve_id: 1
        installments_in_months: 2
        reserve_rate: 1.8
        reserve_release_offset_in_months: 1
        reserve_schedule: ['0.500000000000', '0.500000000000']
        condition: {'transaction_types': [49, 50]}

    ContractReserveDetailWithAccountId:
      title: Contract Reserve Details with Account Id
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractReserveDetail'
        - type: object
          properties:
            account_id:
              type: integer
              description: ID of an account
      example:
        account_id: 1
        contract_id: 1
        contract_reserve_id: 1
        installments_in_months: 2
        reserve_rate: 1.8
        reserve_release_offset_in_months: 1
        reserve_schedule: ['0.500000000000', '0.500000000000']
        condition: {'transaction_types': [49, 50]}

    ContractAdvanceDetail:
      title: Contract Advance Details
      type: object
      properties:
        contract_advance_id:
          type: integer
          description: ID of contract_advance
        contract_id:
          type: integer
          description: ID of contract
        reference_payment_type_id:
          type: integer
          description: ID of the reference payment type
        advance_description:
          type: string
          description: A description for contract advance
        amount:
          type: number
          description: Advance amount
        vat_amount:
          type: number
          description: VAT amount
        withholding_tax_amount:
          type: number
          description: Withholding tax amount, expected to be negative
        amount_after_withholding_and_vat:
          type: number
          description: Amount after withholding tax and VAT, calculated as amount + vat_amount + withholding_tax_amount
            Calculation examples

            amount = 100.00
            vat_amout = 20.00
            withholding_tax_amount = 0.00
            amount_after_withholding_and_vat = 100.00 + 20.00 + 0.00 = 120.00

            amount = 100.00
            vat_amout = 20.00
            withholding_tax_amount = -20.00
            amount_after_withholding_and_vat = 100.00 + 20.00 + -20.00 = 100.00
        us_source_income_rate:
          type: number
          description: US source income %
        currency_code:
          type: string
          description: Alpha-3 iso currency code. default to account's payment currency
        milestone:
          type: string
          description: Either 'contract_execution','delivery','recoupment',
                      'scheduled_installment','sales_milestone' or'other'
        milestone_description:
          type: string
          description: A description for milestone
        milestone_date:
          type: string
          description: This date field indicates whether or not a milestone has been 'reached'.
            If this field is NULL, the milestone has not been reached and the advance cannot be paid.
        advance_status:
          type: string
          description: Either 'not_qualified','qualified','approved','paid' or 'deleted'
        note:
          type: string
          description: A note for advance payment
        created_at:
          type: string
          description: datetime the Contract Advance was created
        created_by:
          type: string
          description: User identity the Contract Advance was created by
      required:
        - contract_id
        - contract_advance_id
        - advance_description
        - amount
        - currency_code
        - milestone
        - milestone_description
        - advance_status
        - created_at
        - created_by
      example:
        contract_id : 1
        contract_advance_id : 1
        advance_description : 'Advance Description'
        amount: 100.00
        vat_amount: 20.00
        withholding_tax_amount: -20.00
        amount_after_withholding_and_vat: 100.00
        currency_code : 'AUD'
        milestone : 'delivery'
        milestone_description : 'Milestone Description'
        advance_status : 'paid'
        created_at: '2022-09-08'
        created_by: 'some_user_id'

    ContractAdvancePaidDetail:
      title: Contract Advance Paid details
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractAdvanceDetail'
        - type: object
          properties:
            statement_period_id:
              type: integer
              description: ID of the statement period for the Date Paid
            advance_payee_currency_code:
              type: integer
              description: Alpha-3 iso currency code. account's payment currency
            advance_amount_payee_currency:
              type: number
              description: the amount of the advance in the account payment currency
            date_paid:
              type: string
              description: the date on which the advance successfully marked as paid
      example:
        contract_id : 1
        statement_period_id: 1
        amount: 100.00
        vat_amount: 20.00
        withholding_tax_amount: -20.00
        amount_after_withholding_and_vat: 100.00
        currency_code : 'AUD'
        advance_payee_currency_code: 'AUD'
        advance_amount_payee_currency: 100.90
        milestone : 'delivery'
        advance_description : 'Advance Description'
        milestone_description : 'Milestone Description'
        advance_status : 'paid'
        created_at: '2022-09-08'
        date_paid: '2022-09-20'

    ReferenceFlowthroughCalculation:
      title: Reference Flowthrough Calculation
      type: object
      properties:
        reference_flowthrough_calculation_id:
          type: integer
          description: ID of the reference flowthrough calculation
        flowthrough_calculation_name:
            type: string
            description: Name of the flowthrough calculation
        flowthrough_calculation:
            type: string
            description: Calculation for flowthrough
        flowthrough_claculation_example:
            type: string
            description: Example of flowthrough calculation
        flowthrough_calculation_description:
            type: string
            description: Description of flowthrough calculation

    ReferenceSapProfitCenterDetail:
      title: SAP Profit Center Details
      type: object
      properties:
        business_group:
          type: string
          description: the profit center's business group
        company_code:
          type: integer
          description: the profit center's company code
        profit_center:
          type: string
          description: alpha-numeric identity of the profit center
        reference_sap_profit_center_id:
          type: integer
          description: royalty_accounting (AKA abacus) ID of the profit_center
      example:
        business_group: 'ORC'
        company_code: 4914
        profit_center: 'UK4914'
        reference_sap_profit_center_id: 1

    ReferencePaymentTypeDetail:
      title: Payment Type Details
      type: object
      properties:
        reference_payment_type_id:
          type: integer
          description: the ID of the Payment Type
        payment_type:
          type: string
          enum: [advance]
          description: Payment type
        payment_service:
          type: string
          description: Payment service
        is_internal:
          type: boolean
          description: internal flag for the payment type
        notes:
          type: string
          description: Payment type description
      example:
        reference_payment_type_id: 1
        payment_type: advance
        payment_service: other
        is_internal: false
        payment_method: 'Other Manual Payment Method'

    ContractLifecycleScheduleDetailResponse:
      title: Contract Lifecycle Schedule Detail GET Response
      type: object
      allOf:
        - type: object
          properties:
            contract_lifecycle_schedule_detail_id:
              type: integer
              description: ID of the contract lifecycle schedule detail
            period_interval:
              type: integer
              description: The interval of the period
            period_type:
              type: string
              description: The type of the period
      example:
        contract_lifecycle_schedule_detail_id: 1
        period_interval: 1
        period_type: 'month'

    ContractLifecycleScheduleDetailDataloaderResponse:
      title: Contract Lifecycle Schedule Detail Dataloader Response
      type: object
      properties:
        data:
          $ref: '#/components/schemas/ContractLifecycleScheduleDetailResponse'

    ContractsDataloaderResponse:
      title: Contracts Dataloader Response
      type: object
      properties:
        data:
          $ref: '#/components/schemas/ContractsDataloaderResponse'

    ContractPartyPostBody:
      title: ContractParty POST request body
      type: object
      properties:
        contract_id:
          type: integer
          description: id of the related contract
        target_id:
          type: string
          description: id of the related target_type
        target_type:
          type: string
          description: must be one of 'contributor', 'label'
      example:
        contract: 1
        target_id: '1ec7c1bf-2318-4052-9406-a3e35a620bd3'
        target_type: 'contributor'

    ContractPartyDetails:
      title: ContractParty Details
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractPartyPostBody'
        - type: object
          properties:
            contract_party_id:
              description: id of the contract_pary
              type: integer
      example:
        contract_party_id: 1
        contract: 1
        target_id: '1ec7c1bf-2318-4052-9406-a3e35a620bd3'
        target_type: 'contributor'

    ContractTermScheduleDetail:
      title: ContractTermSchedule Detail
      type: object
      properties:
        contract_term_schedule_id:
          description: id of contract_term_schedule
          type: integer
        contract_term_id:
          description: id (fk) of the related contract_term
          type: integer
        schedule_id:
          description: id (fk) of the related schedule
          type: integer
      required:
        - contract_term_schedule_id
        - contract_term_id
        - schedule_id
      example:
        contract_term_schedule_id: 1
        contract_term_id: 1
        schedule_id: 1


    ReferencePaymentEntityDetail:
      title: ReferencePaymentEntity Detail
      type: object
      properties:
        reference_payment_entity_id:
          description: id of the reference_payment_entity
          type: integer
        payment_entity_name:
          description: name of the payment entity
          type: string
        country_of_tax_reporting:
          description: code of country where payment entity is reporting for tax
          type: string
      example:
          reference_payment_entity_id: 1
          payment_entity_name: 'AWAL-UK'

    ReferenceTransactionTypeDetail:
      title: Reference Transaction Type Detail
      type: object
      properties:
        reference_transaction_type_id:
          description: The ID of the transaction type
          type: number
        transaction_type_name:
          description: The transaction type name
          type: string
        transaction_type_code:
          description: The code of the transaction type
          type: string
      example:
        reference_transaction_type_id: 1
        transaction_type_name: Subscription Audio Streams
        transaction_type_code: S

    ReferenceTransactionTypeGroupDetail:
      title: Reference Transaction Type Group Detail
      type: object
      properties:
        reference_transaction_type_group_id:
          description: The ID of the transaction type group
          type: number
        transaction_type_group_name:
          description: The name of the transaction type group
          type: string
      example:
        reference_transaction_type_group_id: 1
        transaction_type_group_name: Digital Distribution Streaming

    ContractLifecycleScheduleResponse:
      title: Contract Lifecycle Schedule Response
      type: object
      properties:
        contract_lifecycle_schedule_id:
          description: ID of the contract_lifecycle_schedule
          type: number
        contract_id:
          description: Foreign key to contract table
          type: number
        termination_notice_detail_id:
          description: Foreign key to contract_lifecycle_schedule_detail table
          type: number
        renewal_offset_detail_id:
          description: Foreign key to contract_lifecycle_schedule_detail
          type: number
        collection_period_detail_id:
          description: Foreign key to contract_lifecycle_schedule_detail
          type: number
        renewal_type:
          description: Either continuously_active, renew_after_certain_date or renew_periodically
          type: string
        schedule_end:
          description: End date for contract_lifecycle_schedule and
                      will only have a value when the renewal_type is "renew_after_certain_date"
          type: string
      example:
        contract_lifecycle_schedule_id: 1
        contract_id: 1
        termination_notice_detail_id: 1
        renewal_offset_detail_id: 2
        collection_period_detail_id: 1
        renewal_type: renew_periodically
        schedule_end: '2024-07-12'

    ContractLifecycleScheduleIdsPostBody:
      title: POST request body
      type: array
      items:
        type: integer
        description: ContractLifecycleSchedule ids list
      example:
        [1, 2, 3, 4]

    DataloadedContractLifecycleScheduleList:
      title: Dataloaded ContractLifecycleSchedule list schema
      type: object
      properties:
        data:
          $ref: '#/components/schemas/ContractLifecycleScheduleResponse'

    ContractLifecycleDetail:
      title: Contract Lifecycle Detail
      type: object
      properties:
        contract_lifecycle_id:
          description: ID of the contract_lifecycle
          type: number
        contract_id:
          description: Foreign key to contract table
          type: number
        contract_lifecycle_schedule_id:
          description: Foreign key to contract_lifecycle_schedule table
          type: number
        lifecycle_status:
          description: init, active, to_be_terminated, terminated, in_collection_period or inactive
          type: string
        lifecycle_term_start:
          description: contract's term start date
          type: string
        lifecycle_term_end:
          description: contract's term end date
          type: string
        renewal_effective:
          description: contract's renewal date and it is same as lifecycle_term_end column
          type: string
        termination_notice_deadline:
          description: date indicates how long before the contract ends that a client must inform the business that
            they wish to terminate a contract
          type: string
        termination_notice_received:
          description: date explicitly set by the user when they choose to terminate a contract
          type: string
        termination_effective:
          description: date set by the user when they terminate a contract
          type: string
        collection_start:
          description: date field used by NR contracts only and it will always be the day after the
            lifecycle_term_end
          type: string
        collection_end:
          description: date field used by NR contracts only and is determined using the lifecycle_term_end plus the
            collection_start date
          type: string
      example:
        contract_lifecycle_id: 1
        contract_id: 1
        contract_lifecycle_schedule_id: 1
        lifecycle_status: 'active'
        lifecycle_term_start: '2024-07-03'
        lifecycle_term_end: None
        renewal_effective: None
        termination_notice_deadline: None
        termination_notice_received: None
        termination_effective: None
        collection_start: None
        collection_end: None

    ContractLifecycleIdsPostBody:
      title: POST request body
      type: array
      items:
        type: integer
        description: ContractLifecycle ids list
      example:
        [1, 2, 3, 4]

    ContractLifecyclePutBody:
      title: ContractLifecycle PUT request payload
      type: object
      properties:
        lifecycle_term_start:
          description: Contract's term start date
          type: string
      example:
        lifecycle_term_start: '2024-07-03'

    DataloadedContractLifecycleList:
      title: Dataloaded ContractLifecycle list schema
      type: object
      properties:
        data:
          $ref: '#/components/schemas/ContractLifecycleDetail'

    ContractLifecycleSchedulePostBody:
      title: ContractLifecycleSchedule post request payload
      type: object
      properties:
        termination_notice_detail_interval:
          description: This can be number of days, months or years
          type: number
        termination_notice_detail_type:
          description: Either day, month or year
          type: string
        renewal_offset_detail_interval:
          description: This can be number of days, months or years
          type: number
        renewal_offset_detail_type:
          description: Either day, month or year
          type: string
        collection_period_detail_interval:
          description: This can be number of days, months or years
          type: number
        collection_period_detail_type:
          description: Either day, month or year
          type: string
        renewal_type:
          description: Either continuously_active, renew_after_certain_date or renew_periodically
          type: string
        schedule_end:
          description: End date for contract_lifecycle_schedule and
                      will only have a value when the renewal_type is "renew_after_certain_date"
          type: string
        contract_lifecycle:
          description: Optionally create the contract_lifecycle
          type: object
          allOf:
            - $ref: '#/components/schemas/ContractLifecyclePostBody'
      required:
        - termination_notice_detail_interval
        - termination_notice_detail_type
        - renewal_type
      example:
        termination_notice_detail_interval: 1
        termination_notice_detail_type: 'month'
        renewal_offset_detail_interval: 18
        renewal_offset_detail_type: 'month'
        collection_period_detail_interval: 1
        collection_period_detail_type: 'year'
        renewal_type: 'renew_after_certain_date'
        schedule_end: '2028-06-01'
        contract_lifecycle:
          lifecycle_term_start: '2024-07-03'

    ContractLifecyclePostBody:
      title: ContractLifecycle POST request payload
      type: object
      properties:
        lifecycle_term_start:
          description: contract's term start date
          type: string
      required:
        - lifecycle_term_start
      example:
        lifecycle_term_start: '2024-07-03'

    ContractAndLifecyclePostBody:
      title: ContractAndLifecycle POST request payload
      type: object
      properties:
        contract:
          type: object
          allOf:
            - $ref: '#/components/schemas/ContractPostBody'
        contract_lifecycle_schedules:
          type: array
          items:
            type: object
            allOf:
              - $ref: '#/components/schemas/ContractLifecycleSchedulePostBody'
        contract_lifecycle:
          type: object
          allOf:
            - $ref: '#/components/schemas/ContractLifecyclePostBody'
      required:
        - contract
        - contract_lifecycle_schedules
        - contract_lifecycle

    ContractLifecycleSchedulePutBody:
      title: ContractLifecycleSchedule PUT request payload
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractLifecycleSchedulePostBody'
        - type: object
          properties:
            contract_lifecycle_schedule_id:
              type: integer
              description: ID of the contract_lifecycle_schedule
      required:
        - termination_notice_detail_interval
        - termination_notice_detail_type
        - renewal_type
      example:
        contract_lifecycle_schedule_id: 1
        termination_notice_detail_interval: 1
        termination_notice_detail_type: 'month'
        renewal_offset_detail_interval: 18
        renewal_offset_detail_type: 'month'
        collection_period_detail_interval: 1
        collection_period_detail_type: 'year'
        renewal_type: 'renew_after_certain_date'
        schedule_end: '2028-06-01'

    ReferenceMechanicalRateDetail:
      title: ReferenceMechanicalRate detail
      type: object
      properties:
        reference_mechanical_rate_id:
          type: number
          description: id of the reference_mechanical_rate.
        country_code:
          type: string
          description: 3 character country code.
        base_rate:
          type: string
          description: base mechanical rate.
        minute_rate:
          type: string
          description: per minute mechanical rate.
        ringtone_rate:
          type: string
          description: ringtone rate.
        effective_start_date:
          type: string
          description: start date of the mechanical rate.
      required:
        - reference_mechanical_rate_id
        - country_code
        - base_rate
        - minute_rate
        - ringtone_rate
        - effective_start_date
      example:
        reference_mechanical_rate_id: 1
        country_code: 'USA'
        base_rate: '0.1240'
        minute_rate: '0.0238'
        ringtone_rate: '0.2400'
        effective_start_date: '2004-01-01T00:00:00.000000'

    ActiveContractsByDate:
      title: Active Contracts By Date
      type: object
      properties:
        account_id:
          description: Associated account ID
          type: number
        contract_id:
          description: ID of the contract
          type: number
        term_type:
          description: Type of the term
          type: string
        attachments:
          description: List of attachment identifiers
          type: array
          items:
            type: string
        mechanical_type:
          description: List of mechanical deduction types (e.g., digital, physical)
          type: array
          items:
            type: string
      required:
        - contract_id
        - term_type
        - attachments
        - mechanical_type
      example:
        account_id: 1
        contract_id: 500001
        term_type: 'label'
        attachments: ['9999']
        mechanical_type: ['digital']

    ContractMechanicalDeductionPostBody:
      title: ContractMechanicalDeduction POST request payload
      type: object
      properties:
        territory:
          type: string
          description: 3 character territory code.
        admin_fee:
          type: number
          description: The amount, if any, The Orchard deducts for distribution.
        admin_type:
          type: string
          description: The entity responsible for paying the mechanical deduction. One of 'business', 'customer', or 'both'.
        mechanical_type:
          type: array
          items:
            type: string
          description: List of mechanical deduction types. Either 'digital' or 'physical'.
      required:
        - territory
        - admin_type
        - mechanical_type
      example:
        territory: 'USA'
        admin_fee: '20.20'
        admin_type: 'business'
        mechanical_type: ['digital', 'physical']

    ContractMechanicalDeductionDetail:
      title: ContractMechanicalDeduction detail
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractMechanicalDeductionPostBody'
        - type: object
          properties:
            contract_mechanical_deduction_id:
              type: number
              description: id of the contract_mechanical_deduction.
            contract_id:
              type: number
              description: id of parent contract.
      required:
        - contract_mechanical_deduction_id
        - contract_id
        - territory
        - admin_fee
        - admin_type
        - mechanical_type
      example:
        contract_mechanical_deduction_id: 1
        contract_id: 1
        territory: 'USA'
        admin_fee: '20.20'
        admin_type: 'business'
        mechanical_type: ['digital', 'physical']

    ContractMechanicalDeductionPutBody:
      title: ContractMechanicalDeduction PUT request payload
      type: object
      properties:
        admin_fee:
          type: number
          description: The amount, if any, The Orchard deducts for distribution.
        admin_type:
          type: string
          description: The entity responsible for paying the mechanical deduction. One of 'business', 'customer', or 'both'.
        mechanical_type:
          type: array
          items:
            type: string
          description: List of mechanical deduction types. Either 'digital' or 'physical'.
      required:
        - admin_type
        - mechanical_type
      example:
        admin_fee: '20.20'
        admin_type: 'business'
        mechanical_type: ['digital', 'physical']

    ContractWorldWideMechanicalDeductionPostBody:
      title: ContractMechanicalDeduction POST request payload for worldwide
      type: object
      allOf:
        - $ref: '#/components/schemas/ContractMechanicalDeductionPutBody'
      required:
        - admin_type
        - mechanical_type
      example:
        admin_fee: '20.20'
        admin_type: 'business'
        mechanical_type: ['digital', 'physical']

    ContractFlowthroughDetail:
      title: Contract Flowthrough Detail
      type: object
      properties:
        contract_flowthrough_id:
          description: ID of the contract_flowthrough
          type: number
        contract_id:
          description: Foreign key to contract table
          type: number
        reference_flowthrough_calculation_id:
          description: Foreign key to reference_flowthrough_calculation table
          type: number
        flowthrough_rate:
          description: percentage of revenue that would be paid
          type: string
        flowthrough_status:
          description: active, shutoff, or paused
          type: string
        has_automatic_shutoff:
          description: whether to pay flowthrough. default is True
          type: boolean
        recoupment_cap:
          description: recoupment amount
          type: string
        previous_flowthrough_status:
          description: active, shutoff, or paused
          type: string
        status_last_modified_by:
          description: an identity id of the user who updated the flowthrough status.
          type: string
        status_last_modified:
          description: the date when the flowthrough status is updated
          type: string
      required:
        - contract_flowthrough_id
        - contract_id
        - reference_flowthrough_calculation_id
        - flowthrough_rate
        - flowthrough_status
      example:
        contract_flowthrough_id: 1
        contract_id: 500000
        reference_flowthrough_calculation_id: 1
        flowthrough_rate: 5.10
        flowthrough_status: active
        has_automatic_shutoff: true
        recoupment_cap: 190831
        previous_flowthrough_status: active
        status_last_modified_by: e7d3k7bd-a66h-4151-959f-a65767ccc473
        status_last_modified: 2025-02-28

    ContractFlowthroughPostBody:
      title: Contract Flowthrough POST request body
      type: object
      properties:
        contract_id:
          description: Foreign key to contract table
          type: number
        reference_flowthrough_calculation_id:
          description: Foreign key to reference_flowthrough_calculation table
          type: number
        flowthrough_rate:
          description: percentage of revenue that would be paid
          type: string
        has_automatic_shutoff:
          description: whether to pay flowthrough. default is True
          type: boolean
        recoupment_cap:
          description: recoupment amount
          type: string
      required:
        - contract_id
        - reference_flowthrough_calculation_id
        - flowthrough_rate
        - has_automatic_shutoff
      example:
        contract_id: 500000
        reference_flowthrough_calculation_id: 1
        flowthrough_rate: 5.10
        has_automatic_shutoff: true
        recoupment_cap: 190831

    ContractFlowthroughPutBody:
      title: Contract Flowthrough PUT request body
      type: object
      properties:
        reference_flowthrough_calculation_id:
          description: Foreign key to reference_flowthrough_calculation table
          type: number
        flowthrough_rate:
          description: percentage of revenue that would be paid
          type: string
        flowthrough_status:
          description: active, shutoff, or paused
          type: string
        has_automatic_shutoff:
          description: whether to pay flowthrough. default is True
          type: boolean
        recoupment_cap:
          description: recoupment amount
          type: string
      example:
        contract_id: 500000
        reference_flowthrough_calculation_id: 1
        flowthrough_rate: 5.10
        flowthrough_status: 'active'
        has_automatic_shutoff: true
        recoupment_cap: 190831


    ReferenceTransactionTypeGroupTransactionType:
      title: Reference Transaction Type Group Transaction Type
      type: object
      properties:
          reference_transaction_type_group_transaction_type_id:
            description: ID of the reference_transaction_type_group_transaction_type
            type: number
          reference_transaction_type_group_id:
            description: ID of the reference_transaction_type_group
            type: number
          reference_transaction_type_id:
            description: ID of the reference_transaction_type
            type: number
          reference_transaction_type_group_admin:
            description: group admin for the reference_transaction_type_group_transaction_type
            type: string
      example:
        reference_transaction_type_group_transaction_type_id: 1
        reference_transaction_type_group_id: 1
        reference_transaction_type_id: 1
        reference_transaction_type_group_admin: 'PRESENTATIONAL'

    DagRunTimes:
      title: Dag Run Times response
      type: object
      properties:
          dag_id:
            description: ID of the DAG
            type: string
          count:
            description: the number of runs
            type: number
          average_run_time_seconds:
            description: average time of all the runs for the Dag in seconds
            type: number
          median_run_time_seconds:
            description: median time of all the runs for the Dag in seconds
            type: number
          min_run_time_seconds:
            description: minimum time of all the runs for the Dag in seconds
            type: number
          max_run_time_seconds:
            description: maximum time of all the runs for the Dag in seconds
            type: number
          p95_run_time_seconds:
            description: 95th percentile time of all the runs for the Dag in seconds
            type: number
      example:
        dag_id: 'accounting_run_calculate'
        count: 10
        average_run_time_seconds: 300.5
        median_run_time_seconds: 290.0
        min_run_time_seconds: 250.0
        max_run_time_seconds: 400.0
        p95_run_time_seconds: 390.0
