# schema: https://spec.openapis.org/oas/v3.1.1.html#operation-object
openapi: 3.1.1
info:
  version: 1.0.0
  title: ows-royalties API Specifications
servers:
  - url: 'https://qa-ows-royalties.theorchard.io'
    description: QA server
  - url: 'https://ows-royalties.theorchard.io'
    description: PROD server

paths:

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

  /accounting-period/:
    post:
      summary: Creates a new accounting period with provided data
      requestBody:
        description: The accounting period name
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                accounting_period_name:
                  type: string
                contract_type:
                  type: string
                statement_period_id:
                  type: integer
      responses:
        '201':
          description: CREATED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountingPeriodDetails'
        '400':
          description: Bad data received in payload
        '401':
          description: API key is missing or invalid

  /accounting-periods/:
    get:
      summary: Get list of accounting periods.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/AccountingPeriodDetails'
                  total_count:
                    type: integer

  /accounting-period/{accounting_period_id}/:
    get:
      summary: Retrieves accounting period details
      parameters:
        - description: The id of the accounting period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountingPeriodDetails'
        '404':
          description: 404 NOT FOUND

  /accounting-period/{accounting_period_id}/accounting-period-report/:
    post:
      summary: Create accounting period report or update if such report type exists
      parameters:
        - description: The id of the accounting period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Accounting period report's payload
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountingPeriodReportPostBody'
      responses:
        '201':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountingPeriodReportDetails'
        '400':
          description: Accounting Period does not exist

  /accounting-period/{accounting_period_id}/accounting-period-reports/:
    get:
      summary: Get a list of reports for an accounting period
      parameters:
        - description: The id of the accounting period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/AccountingPeriodReportDetails'
        '400':
          description: Accounting Period does not exist

  /accounting-period/{accounting_period_id}/report-type/{report_type}/accounting-period-report/:
    get:
      summary: Get a specific type of report for an accounting period
      parameters:
        - description: The id of the accounting period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: The type of report ('vat_applied_gbr', 'vat_exempt')
          name: report_type
          in: path
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountingPeriodReportDetails'
        '400':
          description: Accounting Period does not exist; Report type must be one of {}

  /accounting-period/{accounting_period_id}/accounting-runs/:
    get:
      summary: Retrieves accounting run details
      parameters:
      - description: The id of the accounting period
        name: accounting_period_id
        in: path
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/AccountingRunDetails'
        '404':
          description: 404 NOT FOUND

  /accounting-period/{accounting_period_id}/sales-files/:
    get:
      summary: Lists sales files for an accounting period
      parameters:
        - description: The id of the accounting period
          name: accounting_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/AccountingPeriodSalesFileDetail'

  /accounting-run/{accounting_run_id}/:
    get:
      summary: Retrieves accounting run details
      parameters:
        - description: The id of the accounting run
          name: accounting_run_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountingRunDetails'
        '404':
          description: 404 NOT FOUND
    put:
      summary: Updates accounting run status
      parameters:
        - description: The id of the accounting run
          name: accounting_run_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Accounting run properties
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/AccountingRunPutBody'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/AccountingRunDetails'
        '404':
          description: 404 NOT FOUND

  /accounting-run/{accounting_run_id}/accounting-period:
    get:
      summary: Retrieves accounting period details for an associated accounting run.
      parameters:
        - description: The id of the accounting run
          name: accounting_run_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccountingPeriodDetails'
        '404':
          description: 404 NOT FOUND

  /dataloader/statement-periods/:
    post:
      summary: Get a list of statement periods by a list of IDs.
      requestBody:
        description: List of statement period IDs.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [123, 124, 125]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodDetail'
        '400':
          description: Bad data received in payload

  /exchange-rate/bulk-exchange-rates/:
    post:
      summary: Creates exchange rates with provided data
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                exchange_rates:
                  type: string
                statement_period_id:
                  type: integer
      responses:
        '201':
          description: CREATED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ExchangeRates'
        '400':
          description: Bad data received in payload

  /run-controller/:
    post:
      summary: Creates a new run controller
      requestBody:
        description: Run controller's details
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                run_controller_name:
                  type: string
                contract_type:
                  type: string
      responses:
        '201':
          description: CREATED
          content:
            application/json:
              schema:
                type: object
                properties:
                  run_controller_id:
                    type: integer
                  run_controller_name:
                    type: string
                  contract_type:
                    type: string
        '400':
          description: Bad data received in payload

  /run-controllers/:
    get:
      parameters:
        - description: contract type to filter the results by
          name: contract_type
          in: query
          required: false
          schema:
            type: string
          example: distribution
        - description: flag for returning "active" (not-deleted) run controllers
          name: active_only
          in: query
          required: false
          schema:
            type: boolean
          example: true
      summary: Return a list of all run controllers
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      type: object
                      properties:
                        run_controller_id:
                          type: integer
                        run_controller_name:
                          type: string
                        contract_count:
                          type: integer
                        contract_type:
                          type: string
                  total_count:
                    type: integer

  /run-controller/{run_controller_id}/:
    get:
      summary: Get a single run controller.
      parameters:
        - description: The id of the run-controller
          name: run_controller_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RunControllerDetails'
        '404':
          description: No file exists for the given id.

  /run-controller-by-contract/{contract_id}/:
    get:
      summary: Run controller's detail by specified contract_id
      parameters:
        - description: The id of the contract
          name: contract_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                type: object
                properties:
                  run_controller_id:
                    type: integer
                  run_controller_name:
                    type: string
        '404':
          description: NOT FOUND

  /run-controller/contract/:
    post:
      summary: Creates a new reference within contract and run controller
      requestBody:
        description: Reference ids
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/RunControllerContractPostBody'
      responses:
        '201':
          description: CREATED
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RunControllerContractDetails'
        '400':
          description: All of account's distribution contracts must belong to the same run controller...

  /run-controllers/contracts/account/{account_id}/:
    get:
      summary: Get all run_controller_contracts belonging to the specified account
      parameters:
        - description: The account_id
          name: account_id
          in: path
          required: true
          schema:
            type: integer
        - description: The contract type
          name: contract_type
          in: query
          required: false
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
                schema:
                  type: object
                  properties:
                    items:
                      type: array
                      items:
                        type: object
                        properties:
                          contract_id:
                            type: integer
                            description: ID of a contract belonging to the specified account
                          contract_type:
                            type: string
                            description: Type of a contract associated to the run controller
                          run_controller_id:
                            type: integer
                            description: ID of the run controller associated to the contract
                          run_controller_name:
                            type: string
                            description: Name of the run controller associated to the contract
                          contract_count:
                            type: integer
                    total_count:
                      type: integer
        '400':
          description: account_id must be specified

  /run-controllers/contracts/dataloader/:
      post:
        summary: Get a list of run controller 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/RunControllerContractDataloaderResponse'
  /sales-file/:
    post:
      summary: Creates a sales file entry in the current open period.
      requestBody:
        description: Sales file details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SalesFilePostBody'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SalesFileDetail'
        '400':
          description: No open period or duplicate sales file.

  /sales-file/{sales_file_id}/:
    put:
      summary: Update an existing sales file.
      parameters:
        - description: The id of the sales file
          name: sales_file_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        description: Sales file details
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/SalesFilePutBody'
      responses:
        '200':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/SalesFileDetail'
        '400':
          description: Invalid or missing data.
        '404':
          description: No file exists for the given id.

  /statement-periods/recent/:
    get:
      summary: Get the current statement period id and last 6 closed ones
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/RecentStatementPeriodDetail'

  /statement-periods/upcoming/:
    get:
      summary: Get the 24 open statement periods
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodDetail'

  /statement-period/current/:
    get:
      summary: Get the current statement period
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatementPeriodDetail'

  /statement-period/{statement_period_id}/:
    get:
      summary: Get the statement period by statement_period_id
      parameters:
        - description: ID of the statement period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodDetail'

  /statement-period/{statement_period_id}/bulk-exchange-rates:
    get:
      summary: Get exchange rates by statement_period_id
      parameters:
        - description: ID of the statement period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/ExchangeRates'

  /statement-period/{statement_period_id}/close/:
    put:
      summary: Update current statement period to closed and the following one to current.
      parameters:
        - description: The id of the statement period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '201':
          description: OK
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatementPeriodDetail'
        '400':
          description: Statement period must be in 'current' status to be closed.
        '404':
          description: No statement period exists for the given id.

  /statement-period/{statement_period_id}/payment-entities/:
    get:
      summary: Get a list of statement-period-payment-entity records.
      parameters:
        - description: ID of the statement period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodPaymentEntity'

  /statement-period/{statement_period_id}/payment-entities/states/:
    get:
      summary: Get a list of statement_period_payment_entity statuses
      parameters:
        - description: ID of parent statement_period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        200:
          description: success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodPaymentEntityAbacusState'

  /statement-period/{statement_period_id}/payment-entity/{payment_entity_id}/visible/:
    put:
      summary: Sets a record's is_visible_to_customer field to True.
      parameters:
        - description: ID of the statement_period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: ID of the payment_entity
          name: payment_entity_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodPaymentEntity'

  /statement-period-payment-entity/{statement_period_payment_entity_id}:
    get:
      summary: Statement period payment entity details.
      parameters:
        - description: ID of the statement_period_payment_entity
          name: statement_period_payment_entity_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatementPeriodPaymentEntity'

  /statement-period/{statement_period_id}/adjustment-file:
    post:
      summary: Creates statement period adjustment file.
      parameters:
        - description: ID of the statement_period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StatementPeriodAdjustmentFileRequestBody'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatementPeriodAdjustmentFileDetail'

  /statement-period/{statement_period_id}/adjustment-file/{adjustment_file_id}:
    put:
      summary: Updates statement period adjustment file.
      parameters:
        - description: ID of the statement_period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: ID of the adjustment file
          name: adjustment_file_id
          in: path
          required: true
          schema:
            type: integer
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/StatementPeriodAdjustmentFileRequestBody'
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatementPeriodAdjustmentFileDetail'
    get:
      summary: Get statement period adjustment file.
      parameters:
        - description: ID of the statement_period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: ID of the adjustment file
          name: adjustment_file_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatementPeriodAdjustmentFileDetail'
    delete:
      summary: Deletes statement period adjustment file.
      parameters:
        - description: ID of the statement_period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
        - description: ID of the adjustment file
          name: adjustment_file_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '204':
          description: Success

  /statement-period/{statement_period_id}/adjustment-files:
    get:
      summary: Get list of the statement period adjustment files.
      parameters:
        - description: ID of the statement_period
          name: statement_period_id
          in: path
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: object
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/StatementPeriodAdjustmentFileDetail'
                  total_count:
                    type: integer

  /statement-periods/:
    get:
      summary: Get a list of statement periods.
      parameters:
        - in: query
          name: limit
          description: The number of items to return (for pagination)
          schema:
            type: integer
            default: 100
        - in: query
          name: offset
          description: The number of items to skip before returning results (for pagination)
          schema:
            type: integer
            default: 0
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodDetail'
    post:
      summary: GET statement periods by a list of statement_years. Uses POST to allow for a larger list of query args.
      requestBody:
        description: List of statement_years.
        required: true
        content:
          application/json:
            schema:
              type: array
              items:
                  type: number
            example:
              [2024]
      responses:
        '200':
          description: 200 OK
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodDetail'
        '400':
          description: Bad data received in payload

  /statement-period-adjustment-file/{statement_period_adjustment_file_id}:
    get:
      summary: Get a statement_period_adjustment_file by statement_period_adjustment_file_id.
      parameters:
        - in: path
          name: statement_period_adjustment_file_id
          description: id of the statement_period_adjustment_file
          required: true
          schema:
            type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodAdjustmentFileDetail'
    put:
      summary: Update a statement_period_adjustment_file
      parameters:
        - in: path
          name: statement_period_adjustment_file_id
          description: id of the statement_period_adjustment_file to be updated
          required: true
          schema:
            type: integer
      responses:
        201:
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatementPeriodAdjustmentFileDetail'
    delete:
      summary: Delete statement period adjustment file.
      parameters:
        - in: path
          description: ID of the adjustment file
          name: statement_period_adjustment_file_id
          required: true
          schema:
            type: integer
      responses:
        '204':
          description: Success

  /statement-period-adjustment-file/{adjustment_file_id}/download/report:
    get:
      summary: Get the summary report for an adjustment file by statement_period_adjustment_file_id.
      parameters:
      - in: path
        name: adjustment_file_id
        description: id of the statement_period_adjustment_file_id
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodAdjustmentFileReport'
        '400':
            description: Missing data.

  /statement-period-adjustment-file/{adjustment_file_id}/download/error:
    get:
      summary: Get the error report for an adjustment file by statement_period_adjustment_file_id.
      parameters:
      - in: path
        name: adjustment_file_id
        description: id of the statement_period_adjustment_file_id
        required: true
        schema:
          type: integer
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodAdjustmentFileReport'
        '400':
          description: Missing data.

  /abacus-adjustments/download/template:
    get:
      summary: Get a presigned URL to download the abacus adjustments template from S3.
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AdjustmentsTemplate'

  /statement-period-adjustment-files:
    get:
      summary: Get a list of statement period adjustment files.
      parameters:
        - in: query
          name: limit
          description: The number of items to return (for pagination)
          schema:
            type: integer
            default: 100
        - in: query
          name: offset
          description: The number of items to skip before returning results (for pagination)
          schema:
            type: integer
            default: 0
        - in: query
          name: sort_by
          description: Column name by which the results should be sorted
          schema:
            type: string
            default: account_name
        - in: query
          name: sort_order
          description: Order direction (asc or desc)
          schema:
            type: string
            default: asc
        - in: query
          name: status
          description: Status of statement period adjustment file('approved', 'not_approved' or 'applied')
          schema:
            type: string
        - in: query
          name: statement_period_adjustment_file_id
          description: ID of the statement_period_adjustment_file
          schema:
            type: number
        - in: query
          name: file_name
          description: Name of the statement_period_adjustment_file
          schema:
            type: string
        - in: query
          name: statement_period_id
          description: ID of the statement_period
          schema:
            type: number
        - in: query
          name: created_by
          description: Identity Id or Name of the file uploader
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/StatementPeriodAdjustmentFileList'

  /statement-period-adjustment-file/users/{user_action}:
    get:
      summary: Get a list of statement_period_adjustment_file users by user action.
      parameters:
        - in: path
          name: user_action
          description: Must be "uploaded-file"
          required: true
          schema:
            type: string
      responses:
        '200':
          description: Success
          content:
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/StatementPeriodAdjustmentFileUser'

components:
  schemas:
    AccountingPeriodDetails:
      title: Accounting Period details
      type: object
      properties:
        accounting_period_id:
          type: integer
          description: List of accounting runs for the period.
        closed_date:
          type: string
          description: Date the accounting period was closed
        accounting_period_name:
          type: string
          description: Formatted as Name of Month + Year
        accounting_period_status:
          type: string
          enum:
            - open
            - locked
            - closed
        contract_type:
          type: string
          enum:
            - distribution
            - legacy_distribution
            - neighbouring_rights
        statement_period_id:
          type: integer
          description: ID of the statement period
      required:
        - accounting_period_name
        - accounting_period_status
        - contract_type
        - statement_period_id
      example:
        accounting_period_id: 20
        closed_date: null
        accounting_period_name: January 2020
        accounting_period_status: open
        contract_type: distribution
        statement_period_id: 122

    AccountingPeriodReportDetails:
      title: Accounting Period Report details
      type: object
      properties:
        accounting_period_report_id:
          type: integer
          description: ID of the accounting_period_report
        accounting_period_id:
          type: integer
          description: ID of the parent accounting_period
        report_type:
          type: string
          description: The report type (i.e. vat_exempt, vat_applied_gbr)
        report_export_url:
          type: string
          description: the path to the downloadable report on S3
      example:
        accounting_period_report_id: 1
        accounting_period_id: 123
        report_type: vat_exempt
        report_export_url: s3://sales-file-bucket/period/vat/vat_exempt.tsv

    AccountingPeriodReportPostBody:
      title: Accounting Period Report's post request body
      type: object
      properties:
        report_type:
          type: string
          description: The report type (i.e. vat_exempt, vat_applied_gbr)
        report_export_url:
          type: string
          description: the path to the downloadable report on S3
      example:
        report_type: vat_exempt
        report_export_url: s3://sales-file-bucket/period/vat/vat_exempt.tsv

    AccountingRunDetails:
      title: Accounting Run details
      type: object
      properties:
        accounting_period_id:
          type: integer
          description: ID of the accounting period
        accounting_period_name:
          type: string
          description: Name of accounting_period
        accounting_run_id:
          type: integer
          description: ID of the accounting run
        accounting_run_status:
          type: string
          description: Status of the run
        summary_export_url:
          type: string
          description: URL of the summary export
        start_date:
          type: string
          description: Start date of accounting run
        end_date:
          type: string
          description: End date of accounting run
        run_controller_id:
          type: integer
          description: ID of the run controller
        run_controller_name:
          type: string
          description: Name of the run controller
      example:
        accounting_period_id: 20
        accounting_period_name: 'January 2020'
        accounting_run_id: 100
        accounting_run_status: 'No Action Taken'
        run_controller_name: 'Priority'
        run_controller_id: 11
        start_date: "2019-06-01"
        end_date: "2019-06-02"
        summary_export_url: '//s3/path'

    AccountingRunPutBody:
      title: Accounting run put body
      type: object
      properties:
        accounting_run_status:
          $ref: '#/components/schemas/AccountingRunStatus'
        summary_export_url:
          type: string
      required:
        - accounting_run_status
    AccountingRunStatus:
      description: The status of the run
      type: string
      enum:
        - No Action Taken
        - Waiting to Run
        - Running
        - Error
        - Complete
        - Invalid
        - Committed
        - Skipped
        - Sent to Workstation
        - Export Payments

    AdjustmentsTemplate:
      title: Adjustments template download get body
      type: object
      properties:
        template_url:
          type: string
          description: A presigned url to download the template from S3
      example:
        template_url: 'env-abacus-adjustments-s3-url.com'

    RunControllerContractPostBody:
      title: Run Controller Contract post body
      type: object
      properties:
        account_id:
          type: integer
          description: account_id of the contract
        contract_id:
          type: integer
          description: A contract's ID
        run_controller_id:
          type: integer
          description: A run_controller's ID
      required:
        - contract_id
        - run_controller_id
      example:
        account_id: 1
        contract_id: 1
        run_controller_id: 1

    RunControllerContractDetails:
      title: Run Controller Contract details
      type: object
      properties:
        run_controller_contract_id:
          type: integer
          description: The run_controller_contract's ID
        contract_id:
          type: integer
          description: A contract's ID
        run_controller_id:
          type: integer
          description: A run_controller's ID
      example:
        run_controller_contact_id: 1
        contract_id: 1
        run_controller_id: 1

    RunControllerDetails:
      title: Run Controller details
      type: object
      properties:
        run_controller_name:
          type: string
          description: Run controller name
        run_controller_id:
          type: integer
          description: Run controller id
        contract_type:
          type: string
          enum:
            - distribution
            - legacy_distribution
            - neighbouring_rights
          description: Run controller contract type

    SalesFilePostBody:
      title: Sales file post body
      type: object
      properties:
        accounting_period_id:
          type: integer
          description: ID of associated accounting period
        file_name:
          type: string
          description: The name of the sales file
      required:
        - accounting_period_id
        - file_name

    SalesFilePutBody:
      title: Sales file put body
      type: object
      properties:
        amount_usd:
          type: number
          description: The total dollar amount of sales
        main_url:
          type: string
          description: The main location of the sales file on s3
        row_count:
          type: integer
          description: The number of rows in the file

    SalesFileDetail:
      title: Sales file detail
      type: object
      allOf:
        - $ref: '#/components/schemas/SalesFilePutBody'
      properties:
        accounting_period_id:
          type: integer
          description: ID of the parent accounting_period
        file_name:
          type: string
          description: The name of the sales file
        sales_file_id:
          type: integer
          description: ID of the sales_file

    AccountingPeriodSalesFileDetail:
      title: Accounting Period sales file detail
      type: object
      allOf:
        - $ref: '#/components/schemas/SalesFileDetail'
      properties:
        accounting_period_name:
          description: Name of the parent accounting_period
          type: string

    StatementPeriodDetail:
      title: Statement period detail info
      type: object
      properties:
        statement_period_id:
          type: integer
          description: ID of the statement period
        statement_period_name:
          type: string
          description: Name of the statement period
        statement_period_status:
          type: string
          description: Status of the statement period
        statement_month:
          type: number
          description: Statement month of the statement period
        statement_year:
          type: number
          description: Statement year of the statement period
        closed_date:
          type: string
          description: Date when statement period was closed, is specified only for 'closed' statuses
      example:
        statement_period_id: 312
        statement_period_name: December 2024
        statement_period_status: current
        statement_month: 12
        statement_year: 2024
        closed_date: null

    RecentStatementPeriodDetail:
      title: Recent Statement period details
      type: object
      allOf:
        - $ref: '#/components/schemas/StatementPeriodDetail'
        - type: object
          properties:
            exchange_rates_delivered:
              type: boolean
              description: >-
                Represents whether a currency exchange rate file has been delivered
                for the statement period
      example:
        statement_period_id: 312
        statement_period_name: December 2024
        statement_period_status: current
        statement_month: 12
        statement_year: 2024
        closed_date: null
        exchange_rates_delivered: true

    ExchangeRates:
      title: Exchange Rates details
      type: object
      properties:
        exchange_rate_id:
          type: integer
          description: ID of the exchange rate
        from_currency_code:
          type: string
          description: Currency code that needs to be converted
        to_currency_code:
          type: string
          description: Converting from_currency_code to this Currency
        rate:
          type: string
          description: Currency conversion rate

    RunControllerContractDataloaderResponse:
      title: Run Controller Contract dataloader response
      type: object
      properties:
        contract_id:
          type: integer
          description: ID of the contract
        run_controller_id:
          type: integer
          description: ID of the run controller
        run_controller_name:
          type: string
          description: Name of the run controller
        run_controller_contract_id:
          type: integer
          description: ID of the run controller contract
      example:
        contract_id: 1
        run_controller_id: 1
        run_controller_name: 'run_controller_contract_name'
        run_controller_contract_id: 1


    StatementPeriodPaymentEntity:
      title: Statement Period Payment Entity details
      type: object
      properties:
        statement_period_payment_entity_id:
          type: integer
          description:  Unique ID of the statement_period_payment_entity
        statement_period_id:
          type: integer
          description: ID of the statement_period
        payment_entity_id:
          type: integer
          description: ID of the payment_entity
        reference_payment_entity_id:
          type: integer
          description: ID of the related reference_payment_entity
        is_visible_to_customer:
          type: boolean
          description: Represents whether the payment entity should be visible to the customer for this statement period.

    StatementPeriodPaymentEntityAbacusState:
      title: Statement Period Payment Entity state details
      type: object
      properties:
        statement_period_payment_entity_id:
          description:  Unique ID of the statement_period_payment_entity
          type: integer
        statement_period_id:
          description: ID of the statement_period
          type: integer
        reference_payment_entity_id:
          description: ID of the related reference_payment_entity
          type: integer
        abacus_state_id:
          description: ID of the abacus_state record
          type: integer
        action_name:
          description: name of the abacus_state action
          type: string
        action_status:
          description: status of the abacus_state action
          type: string
      example:
        statement_period_payment_entity_id: 1
        statement_period_id: 300
        reference_payment_entity_id: 1
        abacus_state_id: 1000
        action_name: 'close_balance'
        action_status: 'complete'

    StatementPeriodAdjustmentFileDetail:
      title: Statement period adjustment file info
      type: object
      properties:
        statement_period_adjustment_file_id:
          type: integer
          description: ID of the statement period adjustment file
        statement_period_id:
          type: integer
          description: ID of the statement period
        file_name:
          type: string
          description: File name
        valid_file_location:
          type: string
          description: Location of the valid adjustment file on S3
        invalid_file_location:
          type: string
          description: Location of the invalid adjustment file on S3
        valid_row_count:
          type: integer
          description: Total number of valid rows in the adjustment file
        invalid_row_count:
          type: integer
          description: Total number of invalid rows in the adjustment file
        valid_row_amount:
          type: number
          description: Total amount of valid rows in the adjustment file
        invalid_row_amount:
          type: number
          description: Total amount of invalid rows in the adjustment file
        md5sum:
          type: string
          description: MD5 checksum
        error_type:
          type: string
          description: the type of the error; one of 'format_error', 'content_error', or 'row_count_error'
      example:
        statement_period_adjustment_file_id: 1
        statement_period_id: 1
        file_name: 'some_file.csv'
        valid_file_location: 'some/location'
        valid_row_count: 10
        valid_row_amount: 1100.01
        md5sum: 'b6579ec2950296ed6a04f08f67f64422'
        error_type: null

    StatementPeriodAdjustmentFileRequestBody:
      title: Statement period adjustment create request body
      type: object
      properties:
        file_name:
          type: string
          description: File name
        valid_file_location:
          type: string
          description: Location of the valid adjustment file on S3
        invalid_file_location:
          type: string
          description: Location of the invalid adjustment file on S3
        valid_row_count:
          type: integer
          description: Total number of valid rows in the adjustment file
        invalid_row_count:
          type: integer
          description: Total number of invalid rows in the adjustment file
        valid_row_amount:
          type: number
          description: Total amount of valid rows in the adjustment file
        invalid_row_amount:
          type: number
          description: Total amount of invalid rows in the adjustment file
        md5sum:
          type: string
          description: MD5 checksum
      example:
        file_name: 'some_file.csv'
        valid_file_location: 'some/location'
        valid_row_count: 10
        valid_row_amount: 1100.01
        md5sum: 'b6579ec2950296ed6a04f08f67f64422'

    StatementPeriodAdjustmentFileList:
      title: Statement period adjustment file info
      type: object
      properties:
        status:
          type: string
          description: Status of statement period adjustment file
        valid_row_count:
          type: number
          description: Total number of valid rows in the adjustment file
        statement_period_adjustment_file_id:
          type: string
          description: ID of the statement_period_adjustment_file
        statement_period_id:
          type: integer
          description: ID of the statement period
        file_name:
          type: string
          description: File name
        total_rounded_amount_multicurrency:
          type: string
          description: String representation of rounded total amount from valid rows in the adjustment file
        created_at:
          type: string
          description: Date when the file was uploaded to the system
        created_by:
          type: string
          description: Identity Id of the uploader
        date_approved:
          type: string
          description: Date when the adjustment file has been approved
        approved_by:
          type: string
          description: Identity Id of the user who approved
        date_applied:
          type: string
          description: Date when the adjustments has been applied
        applied_by:
          type: string
          description: Identity Id of the user who applied
      example:
        status: 'Not Approved'
        valid_row_count: 10
        statement_period_adjustment_file_id: 256
        statement_period_id: 2
        file_name: 'test_file_name.xlsx'
        total_rounded_amount_multicurrency: '1100.01'
        created_at: '2023-10-20'
        created_by: 'Test User'
        date_approved: '2023-11-20'
        approved_by: 'Joe User'
        date_applied: '2023-11-28'
        applied_by: 'Joe User'

    StatementPeriodAdjustmentFileReport:
      title: Statment Period Adjustment File download get body
      type: object
      properties:
        template_url:
          type: string
          description: A presigned url to download the report from S3
      example:
        template_url: 'env-abacus-adjustments-s3-url.com'

    StatementPeriodAdjustmentFileUser:
      title: Identity id or name of the user
      type: object
      properties:
        created_by:
          type: string
          description: Identity Id or Name of the file uploader
      example:
        created_by: 'e5ca8bc3-7e52-4793-8775-50d11282504c'
