# Proposed contract, version 1: endpoints, errors, paging, idempotency, security and the capability of every
# operation. Resource schemas were initialized from the data model (docs/06-data) and are kept aligned with it; input
# schemas (*Input, *Request) and views are specific to this contract. Status: proposal for review, not confirmed design.
# Conventions: docs/05-interfaces/choosing-an-interface.md. Vendor extensions: x-moonitoring-audience (who calls),
# x-moonitoring-capability (the capability checked), x-moonitoring-entitlement (the entitlement feature checked),
# x-moonitoring-requirements (the requirements of 1.requisiti-raffinati.txt the operation serves).
openapi: 3.1.0
info:
  title: Farm Events API
  version: 1.0.0
  description: What happened to an animal or a group, as each feed reported it (calvings, services, treatments,
    exits and the other canonical events), the periods derived from the resolved facts (lactations, dry periods,
    pregnancies, withdrawals), the catalogs of period and death kinds and each farm's configuration. Consumers who
    want one fact per real event read the Reconciliation API.
servers:
- url: https://farm.moonitoring.com/events/v1
  description: Prod
- url: https://stage-farm.moonitoring.com/events/v1
  description: Stage, through IAP
security:
- bearer: []
tags:
- name: Events
  description: Canonical events, one per feed
- name: Periods
  description: States with a start and an end
- name: Catalogs
  description: Period and death kinds
- name: Configuration
  description: Farm context over time
paths:
  /organizations/{organization_id}/events:
    get:
      summary: List events
      operationId: listEvents
      description: Evidence as each feed reported it; several events may describe one real fact. For one fact per
        event read resolved events.
      tags:
      - Events
      parameters:
      - name: organization_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
        description: 'The farm: the token''s active Organization, or a farm that delegated to it.'
      - name: animal
        in: query
        required: false
        schema:
          type: string
          format: uuid
        description: Only this animal.
      - name: animal_group
        in: query
        required: false
        schema:
          type: string
          format: uuid
        description: Only this group.
      - name: type
        in: query
        required: false
        schema:
          type: string
          enum:
          - HerdEntryEvent
          - HerdExitEvent
          - ServiceEvent
          - PregnancyCheckEvent
          - ParturitionEvent
          - AbortionEvent
          - DryOffEvent
          - HeatEvent
          - DiagnosisEvent
          - TreatmentEvent
          - HealthCheckEvent
          - BreedingStatusEvent
          - GroupTreatmentEvent
          - GroupMovementEvent
          - ProductEvent
        description: Only this kind.
      - name: status
        in: query
        required: false
        schema:
          type: string
          enum:
          - active
          - corrected
          - cancelled
        description: Only this status.
      - name: feed
        in: query
        required: false
        schema:
          type: string
          format: uuid
        description: Only events of this feed.
      - name: from
        in: query
        required: false
        schema:
          type: string
          format: date-time
        description: Records whose time is at or after.
      - name: to
        in: query
        required: false
        schema:
          type: string
          format: date-time
        description: Records whose time is before.
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/AsOfSeq
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Cursor
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Limit
      responses:
        '200':
          description: One page of results.
          content:
            application/json:
              schema:
                type: object
                description: One page of items.
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/CanonicalEvent'
                  next_cursor:
                    type: string
                    description: Where the next page starts; absent on the last page.
                required:
                - items
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '28'
      - 28.*.1
      - 28.*.2
      - '1002.11'
      - '1006.23'
    post:
      summary: Record an event
      operationId: recordEvent
      description: '`farm.animal_events.record` covers entry, exit, service, pregnancy check, parturition, abortion,
        dry-off, heat and breeding status; `farm.animal_diagnoses.record` covers diagnosis, health check and treatment,
        for an animal or a group.'
      tags:
      - Events
      parameters:
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/IdempotencyKey
      - name: organization_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
        description: 'The farm: the token''s active Organization, or a farm that delegated to it.'
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EventEntry'
      responses:
        '201':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CanonicalEvent'
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
        '409':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Conflict
        '422':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/UnprocessableEntity
      x-moonitoring-audience: organization
      x-moonitoring-capability:
      - farm.animal_events.record
      - farm.animal_diagnoses.record
      x-moonitoring-requirements:
      - '28'
      - 32.*.4
      - 19.*.2
      - '1002.12'
      - '1002.13'
  /events/{event_id}:
    get:
      summary: Read an event
      operationId: getEvent
      tags:
      - Events
      parameters:
      - name: event_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/AsOfSeq
      responses:
        '200':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CanonicalEvent'
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '28'
  /events/{event_id}/revisions:
    get:
      summary: List an event's revisions
      operationId: listEventRevisions
      tags:
      - Events
      parameters:
      - name: event_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Cursor
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Limit
      responses:
        '200':
          description: One page of results.
          content:
            application/json:
              schema:
                type: object
                description: One page of items.
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/CanonicalEvent'
                  next_cursor:
                    type: string
                    description: Where the next page starts; absent on the last page.
                required:
                - items
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '28.5'
      - '1019'
  /events/{event_id}/lineage:
    get:
      summary: Read an event's lineage
      operationId: getEventLineage
      tags:
      - Events
      parameters:
      - name: event_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      responses:
        '200':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/EventLineage'
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '28.2'
      - '28.6'
      - '28.7'
      - '28.8'
      - '17'
      - '30'
      - '61'
  /events/{event_id}/offspring:
    get:
      summary: List the offspring of a parturition
      operationId: listEventOffspring
      tags:
      - Events
      parameters:
      - name: event_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Cursor
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Limit
      responses:
        '200':
          description: One page of results.
          content:
            application/json:
              schema:
                type: object
                description: One page of items.
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/Offspring'
                  next_cursor:
                    type: string
                    description: Where the next page starts; absent on the last page.
                required:
                - items
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '39'
  /events/{event_id}/products:
    get:
      summary: List the products of a treatment
      operationId: listEventProducts
      tags:
      - Events
      parameters:
      - name: event_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Cursor
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Limit
      responses:
        '200':
          description: One page of results.
          content:
            application/json:
              schema:
                type: object
                description: One page of items.
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/TreatmentProduct'
                  next_cursor:
                    type: string
                    description: Where the next page starts; absent on the last page.
                required:
                - items
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '40'
      - '1015'
  /events/{event_id}/correct:
    post:
      summary: Correct an event
      operationId: correctEvent
      description: Only events that entered through the Organization's own feeds.
      tags:
      - Events
      parameters:
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/IdempotencyKey
      - name: event_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/EventCorrectionRequest'
      responses:
        '201':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CanonicalEvent'
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
        '409':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Conflict
        '422':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/UnprocessableEntity
      x-moonitoring-audience: organization
      x-moonitoring-capability: farm.animal_records.edit_own
      x-moonitoring-requirements:
      - '28.5'
      - '1002.20'
      - '61.3'
  /events/{event_id}/cancel:
    post:
      summary: Cancel an event
      operationId: cancelEvent
      tags:
      - Events
      parameters:
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/IdempotencyKey
      - name: event_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CancellationRequest'
      responses:
        '201':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CanonicalEvent'
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
        '409':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Conflict
        '422':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/UnprocessableEntity
      x-moonitoring-audience: organization
      x-moonitoring-capability: farm.animal_records.edit_own
      x-moonitoring-requirements:
      - '28.5'
      - '1002.20'
      - '61.3'
  /organizations/{organization_id}/periods:
    get:
      summary: List periods
      operationId: listPeriods
      tags:
      - Periods
      parameters:
      - name: organization_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
        description: 'The farm: the token''s active Organization, or a farm that delegated to it.'
      - name: animal
        in: query
        required: false
        schema:
          type: string
          format: uuid
        description: Only this animal.
      - name: animal_group
        in: query
        required: false
        schema:
          type: string
          format: uuid
        description: Only this group.
      - name: period_type
        in: query
        required: false
        schema:
          type: string
          format: uuid
        description: Only this kind, e.g. lactation.
      - name: status
        in: query
        required: false
        schema:
          type: string
          enum:
          - open
          - closed
          - unknown
          - cancelled
        description: Only this status.
      - name: open_at
        in: query
        required: false
        schema:
          type: string
          format: date-time
        description: Only periods that include this time.
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/AsOfSeq
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Cursor
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Limit
      responses:
        '200':
          description: One page of results.
          content:
            application/json:
              schema:
                type: object
                description: One page of items.
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/CanonicalPeriod'
                  next_cursor:
                    type: string
                    description: Where the next page starts; absent on the last page.
                required:
                - items
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '31'
      - 31.*.1
      - 31.*.2
      - '1002.11'
  /periods/{period_id}:
    get:
      summary: Read a period
      operationId: getPeriod
      tags:
      - Periods
      parameters:
      - name: period_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/AsOfSeq
      responses:
        '200':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CanonicalPeriod'
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '31'
  /period-types:
    get:
      summary: List period kinds
      operationId: listPeriodTypes
      tags:
      - Catalogs
      parameters:
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Cursor
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Limit
      responses:
        '200':
          description: One page of results.
          content:
            application/json:
              schema:
                type: object
                description: One page of items.
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/PeriodType'
                  next_cursor:
                    type: string
                    description: Where the next page starts; absent on the last page.
                required:
                - items
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
      x-moonitoring-audience: any
      x-moonitoring-capability: null
      x-moonitoring-requirements:
      - '42'
    post:
      summary: Create a period kind
      operationId: createPeriodType
      tags:
      - Catalogs
      parameters:
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/IdempotencyKey
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/PeriodTypeInput'
      responses:
        '201':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/PeriodType'
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '409':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Conflict
        '422':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/UnprocessableEntity
      x-moonitoring-audience: staff
      x-moonitoring-capability: farm.reference_data.manage
      x-moonitoring-requirements:
      - '42'
      - '1006.17'
  /death-types:
    get:
      summary: List death kinds
      operationId: listDeathTypes
      tags:
      - Catalogs
      parameters:
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Cursor
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Limit
      responses:
        '200':
          description: One page of results.
          content:
            application/json:
              schema:
                type: object
                description: One page of items.
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/DeathType'
                  next_cursor:
                    type: string
                    description: Where the next page starts; absent on the last page.
                required:
                - items
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
      x-moonitoring-audience: any
      x-moonitoring-capability: null
      x-moonitoring-requirements:
      - '29'
    post:
      summary: Create a death kind
      operationId: createDeathType
      tags:
      - Catalogs
      parameters:
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/IdempotencyKey
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/DeathTypeInput'
      responses:
        '201':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/DeathType'
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '409':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Conflict
        '422':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/UnprocessableEntity
      x-moonitoring-audience: staff
      x-moonitoring-capability: farm.reference_data.manage
      x-moonitoring-requirements:
      - '29'
      - '1006.17'
  /organizations/{organization_id}/configurations:
    get:
      summary: List a farm's configurations
      operationId: listFarmConfigurations
      tags:
      - Configuration
      parameters:
      - name: organization_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
        description: The Farm.
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/AsOfSeq
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Cursor
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/Limit
      responses:
        '200':
          description: One page of results.
          content:
            application/json:
              schema:
                type: object
                description: One page of items.
                properties:
                  items:
                    type: array
                    items:
                      $ref: '#/components/schemas/FarmConfiguration'
                  next_cursor:
                    type: string
                    description: Where the next page starts; absent on the last page.
                required:
                - items
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
      x-moonitoring-audience: any
      x-moonitoring-capability:
      - farm.animal_records.read
      - farm.canonical_data.read_all
      x-moonitoring-requirements:
      - '43'
    post:
      summary: Add a farm configuration period
      operationId: createFarmConfiguration
      description: The previous period closes at the new start.
      tags:
      - Configuration
      parameters:
      - $ref: ../../../../common/v1/schemas.yaml#/components/parameters/IdempotencyKey
      - name: organization_id
        in: path
        required: true
        schema:
          type: string
          format: uuid
        description: The Farm.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/FarmConfigurationInput'
      responses:
        '201':
          description: The result.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/FarmConfiguration'
        '400':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/BadRequest
        '401':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Unauthorized
        '403':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Forbidden
        '404':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/NotFound
        '409':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/Conflict
        '422':
          $ref: ../../../../common/v1/schemas.yaml#/components/responses/UnprocessableEntity
      x-moonitoring-audience: organization
      x-moonitoring-capability: farm.farm_configurations.manage
      x-moonitoring-requirements:
      - '43'
      - '43.4'
components:
  schemas:
    CanonicalEvent:
      description: 'Something that happened to an animal, a group or a product lot at a point in time, as reported
        by one feed: a calving, a service, a treatment, an exit from the herd. Events are evidence: several of them
        can describe the same fact, and they are joined into a resolved event, which is what consumers read.'
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Key.
        source_producer:
          type: string
          format: uuid
          description: ID of the SourceProducerEntity. The producer of the canonical event.
        occurred:
          allOf:
          - $ref: ../../../../common/v1/schemas.yaml#/components/schemas/EventTime
          description: 'When it happened, with its precision: many sources give only a date.'
        recorded_at:
          type: string
          format: date-time
          description: When it was entered at the source; may differ from occurred (e.g. inseminations are registered
            4-19 days late, median per farm). Empty when the source does not say (e.g. SiAlleva exits); never filled
            with an assumed delay.
        status:
          type: string
          enum:
          - active
          - corrected
          - cancelled
          default: active
          description: 'Sources resend and correct events; a correction never deletes history. `cancelled`: a verified
            authoritative full snapshot proves removal (SyncRun), or the source sent an explicit deletion.'
        raw_metadata:
          type: string
          format: uuid
          description: ID of the RawMetadata. Required unless computed by us (e.g. our heat alert); see lineage.
        raw_locator:
          type: string
        source_record_key:
          type: string
          description: Logical identity (`source_feed`, `source_record_key`); historical uniqueness adds revision
            number. Source-key recipes are documented; collisions are issues, not automatically duplicate events.
        source_code:
          type: string
          description: The provider's own code for the event (e.g. AfiFarm 30017, DairyComp PARTO), for traceability.
            Map documented meaning and export version, not labels. Provider-specific findings become adapter tests.
            Later outcomes on earlier services become known at their revision availability, not the service date.
        source_feed:
          type: string
          format: uuid
          description: ID of the SourceFeed.
        content_hash:
          type: string
          description: Same rule as `CanonicalObservation.content_hash`.
        revision:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/RecordRevision
        farm:
          type: string
          format: uuid
          description: ID of the Organization that is a Farm. The farm of the feed that delivered the record (=
            `source_feed.farm`), copied here as the key of partitioning, row-level access and erasure; it never
            changes on a revision. See STORAGE. For events we compute (e.g. our heat alert), the farm of the inputs.
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        subject:
          type: string
          enum:
          - AnimalEvent
          - AnimalGroupEvent
          - ProductEvent
          description: Which kind of CanonicalEvent this is (enum, disjoint + complete).
      required:
      - id
      - source_producer
      - occurred
      - status
      - source_record_key
      - source_feed
      - content_hash
      - revision
      - farm
      - created_at
      - updated_at
      - subject
    AnimalEvent:
      allOf:
      - $ref: '#/components/schemas/CanonicalEvent'
      - type: object
        properties:
          animal:
            type: string
            format: uuid
            description: ID of the Animal.
          type:
            type: string
            enum:
            - HerdEntryEvent
            - HerdExitEvent
            - ServiceEvent
            - PregnancyCheckEvent
            - ParturitionEvent
            - AbortionEvent
            - DryOffEvent
            - HeatEvent
            - DiagnosisEvent
            - TreatmentEvent
            - HealthCheckEvent
            - BreedingStatusEvent
            description: Which kind of AnimalEvent this is (enum, disjoint + complete).
        required:
        - animal
        - type
      description: A CanonicalEvent whose subject is AnimalEvent.
    HerdEntryEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          entry_reason:
            type: string
            enum:
            - purchase
            - transfer_in
            - other
            - unknown
        required:
        - entry_reason
      description: A AnimalEvent whose type is HerdEntryEvent.
    HerdExitEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          exit_type:
            type: string
            enum:
            - sale_alive
            - transfer_out
            - sent_to_slaughter
            - emergency_slaughter
            - slaughter_confirmed
            - death
            - other
            - unknown
            description: 'Map each country''s export explicitly; dispatch to slaughter does not prove confirmed
              slaughter. `emergency_slaughter`: slaughter of an injured or sick animal under the veterinary emergency
              rules (in Italy code 5). A source code may change meaning by farm and period (e.g. one farm records
              planned culls as transfers since 2018; code 5 rules changed in 2022 and 2026): parser mappings can
              be scoped by farm and validity period, and `source_code` is kept so the mapping can be re-applied.'
          death_type:
            type: string
            format: uuid
            description: ID of the DeathType. Only when `exit_type` = death.
          cause:
            type: string
          destination:
            type: string
          management_episode:
            type: string
            format: uuid
            description: ID of the Ownership that is a AnimalOwnership.
          exited_group:
            type: string
            format: uuid
            description: ID of the AnimalGroup.
        required:
        - exit_type
      description: A AnimalEvent whose type is HerdExitEvent.
    ServiceEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          service_method:
            type: string
            enum:
            - artificial_insemination
            - natural_service
            - embryo_transfer
            - unknown
          sire:
            $ref: ../../../../common/v1/schemas.yaml#/components/schemas/ParentReference
          semen_type:
            type: string
            enum:
            - conventional
            - sexed_female
            - sexed_male
            - unknown
            default: unknown
            description: Sexed semen of both sexes is sold (SiAlleva `Sex Fem`, `Sex Msc`).
          embryo_donor:
            allOf:
            - $ref: ../../../../common/v1/schemas.yaml#/components/schemas/ParentReference
            description: 'Only for `embryo_transfer`: the genetic mother. The animal of the event is the recipient.'
          reported_outcome:
            allOf:
            - $ref: ../../../../common/v1/schemas.yaml#/components/schemas/CodedValue
            description: Known at this revision's availability, not a new examination without evidence.
        required:
        - service_method
        - semen_type
      description: A AnimalEvent whose type is ServiceEvent.
    PregnancyCheckEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          result:
            type: string
            enum:
            - pregnant
            - not_pregnant
            - uncertain
          related_service:
            type: string
            format: uuid
            description: ID of the CanonicalEvent that is a ServiceEvent.
        required:
        - result
      description: A AnimalEvent whose type is PregnancyCheckEvent.
    ParturitionEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          related_service:
            type: string
            format: uuid
            description: ID of the CanonicalEvent that is a ServiceEvent. The service that caused the pregnancy.
              Official PA/PN codes depend on it.
          calving_ease:
            allOf:
            - $ref: ../../../../common/v1/schemas.yaml#/components/schemas/CodedValue
            description: Code plus code system, e.g. ICAR, PRES A-E, Lely BreCode.
          offspring:
            type: array
            items:
              type: string
              format: uuid
            description: ID of the Offspring. One row per newborn, alive or dead.
      description: A AnimalEvent whose type is ParturitionEvent.
    AbortionEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          related_service:
            type: string
            format: uuid
            description: ID of the CanonicalEvent that is a ServiceEvent. Official AA/AY codes depend on it.
      description: A AnimalEvent whose type is AbortionEvent.
    DryOffEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      description: A AnimalEvent whose type is DryOffEvent.
    HeatEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          detection:
            type: string
            enum:
            - visual
            - sensor_alert
            - unknown
        required:
        - detection
      description: A AnimalEvent whose type is HeatEvent.
    DiagnosisEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          condition:
            $ref: ../../../../common/v1/schemas.yaml#/components/schemas/CodedValue
          body_site:
            type: string
            format: uuid
            description: ID of the BodySite.
          supporting_observations:
            type: array
            items:
              type: string
              format: uuid
            description: ID of the CanonicalObservation. Observations used as evidence, e.g. a lab SCC. The diagnosis
              points to them, not the opposite.
        required:
        - condition
      description: A AnimalEvent whose type is DiagnosisEvent.
    TreatmentEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          treatment_kind:
            type: string
            enum:
            - drug
            - vaccination
            - procedure
            - reproductive_protocol
          related_diagnosis:
            type: string
            format: uuid
            description: ID of the CanonicalEvent that is a DiagnosisEvent.
          body_site:
            type: string
            format: uuid
            description: ID of the BodySite.
          ends_at:
            $ref: ../../../../common/v1/schemas.yaml#/components/schemas/EventTime
          products:
            type: array
            items:
              type: string
              format: uuid
            description: ID of the TreatmentProduct.
        required:
        - treatment_kind
      description: A AnimalEvent whose type is TreatmentEvent.
    HealthCheckEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          finding:
            $ref: ../../../../common/v1/schemas.yaml#/components/schemas/CodedValue
      description: A AnimalEvent whose type is HealthCheckEvent.
    BreedingStatusEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalEvent'
      - type: object
        properties:
          status:
            type: string
            enum:
            - ok_to_breed
            - do_not_breed
        required:
        - status
      description: A AnimalEvent whose type is BreedingStatusEvent.
    AnimalGroupEvent:
      allOf:
      - $ref: '#/components/schemas/CanonicalEvent'
      - type: object
        properties:
          group:
            type: string
            format: uuid
            description: ID of the AnimalGroup. A group event without a group is meaningless.
          type:
            type: string
            enum:
            - GroupTreatmentEvent
            - GroupMovementEvent
            description: Which kind of AnimalGroupEvent this is (enum, disjoint).
        required:
        - group
      description: A CanonicalEvent whose subject is AnimalGroupEvent.
    GroupTreatmentEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalGroupEvent'
      - type: object
        properties:
          treatment_kind:
            type: string
            enum:
            - drug
            - vaccination
            - procedure
          products:
            type: array
            items:
              type: string
              format: uuid
            description: ID of the TreatmentProduct.
        required:
        - treatment_kind
      description: A AnimalGroupEvent whose type is GroupTreatmentEvent.
    GroupMovementEvent:
      allOf:
      - $ref: '#/components/schemas/AnimalGroupEvent'
      - type: object
        properties:
          direction:
            type: string
            enum:
            - entry
            - exit
          count:
            type: integer
            description: Greater than 0.
          reason:
            type: string
            enum:
            - placement
            - purchase
            - transfer
            - sale_alive
            - sent_to_slaughter
            - emergency_slaughter
            - death
            - culling
            - other
            - unknown
            description: Placement and purchase only for entry; the others only for exit except transfer and other.
          destination:
            type: string
        required:
        - direction
        - count
        - reason
      description: Future work. A AnimalGroupEvent whose type is GroupMovementEvent.
    ProductEvent:
      allOf:
      - $ref: '#/components/schemas/CanonicalEvent'
      - type: object
        properties:
          product_material:
            type: string
            format: uuid
            description: ID of the ProductMaterial.
        required:
        - product_material
      description: Future work. A CanonicalEvent whose subject is ProductEvent.
    Offspring:
      description: One newborn of a parturition, alive or dead. Twins are two rows; a stillborn calf may never become
        an animal, while a registered calf links to its animal record.
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Key.
        parturition:
          type: string
          format: uuid
          description: ID of the CanonicalEvent that is a ParturitionEvent.
        animal:
          type: string
          format: uuid
          description: ID of the Animal. The registered animal, when the newborn was registered.
        sex:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/AnimalSexEnum
        viability:
          type: string
          enum:
          - alive
          - stillborn
          - died_after_birth
          - unknown
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
      - id
      - parturition
      - viability
      - created_at
      - updated_at
    TreatmentProduct:
      description: One product used in a treatment, with dose, route, quantity taken from stock and withdrawal periods
        (how long milk or meat from the animal cannot be sold afterwards).
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Key.
        product_code:
          type: string
          description: Official medicine code when known (e.g. the Italian AIC code).
        product_name:
          type: string
        dose:
          type: number
        dose_unit:
          type: string
          description: UCUM or a package unit (tube, dose, piece).
        dose_basis:
          type: string
          enum:
          - per_animal
          - per_100kg_bodyweight
          - per_quarter
          - total
          - unknown
          default: unknown
          description: e.g. "20 ML / 100 Kg" = dose 20, unit mL, basis `per_100kg_bodyweight`; "1 TUBO X QUARTO"
            = `per_quarter`.
        total_quantity:
          type: number
          description: Total quantity unloaded from stock for this treatment, in `dose_unit`.
        route:
          type: string
          enum:
          - injection
          - oral
          - intramammary
          - topical
          - intrauterine
          - other
          - unknown
        withdrawals:
          type: array
          items:
            $ref: ../../../../common/v1/schemas.yaml#/components/schemas/WithdrawalSpec
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
      - id
      - product_name
      - dose_basis
      - route
      - created_at
      - updated_at
    DeathType:
      description: Catalog of the kinds of death recorded when an animal leaves the herd because it died.
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Key.
        name:
          type: string
          description: Unique.
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
      - id
      - name
      - created_at
      - updated_at
    CanonicalPeriod:
      description: 'A state of an animal or group with a start and an end: a lactation, a dry period, a pregnancy,
        a withdrawal. Periods are usually computed from resolved events, and recomputed when a resolution changes.'
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Key.
        period_type:
          type: string
          format: uuid
          description: ID of the PeriodType.
        period:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/ObservedPeriod
        start_event:
          type: string
          format: uuid
          description: 'ID of the ResolvedEvent. Optional: some periods start before our data or without a recorded
            event. Points to the resolved fact, not to one source''s evidence. Periods are recomputed when a resolution
            changes.'
        end_event:
          type: string
          format: uuid
          description: ID of the ResolvedEvent. e.g. the DryOffEvent or HerdExitEvent that closed a lactation.
        status:
          type: string
          enum:
          - open
          - closed
          - unknown
          - cancelled
          description: Open requires explicitly open end; unknown end is not open; cancelled remains in history.
        ordinal_reported:
          type: integer
          description: Number given by the source, e.g. lactation number.
        ordinal_computed:
          type: integer
          description: Number computed by us; kept separately because the two can disagree.
        source_producer:
          type: string
          format: uuid
          description: ID of the SourceProducerEntity. Usually a ComputedSourceOrigin when we derive the period
            from events.
        revision:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/RecordRevision
        derivation:
          type: string
          format: uuid
          description: ID of the CanonicalDerivation. Required for computed periods; inputs identify exact resolved-event
            revisions.
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        subject:
          type: string
          enum:
          - AnimalPeriod
          - AnimalGroupPeriod
          description: Which kind of CanonicalPeriod this is (enum, disjoint + complete).
        withdrawal_details:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/WithdrawalSpec
        raw_metadata:
          type: string
          format: uuid
          description: ID of the RawMetadata. Required for periods reported by a source; computed periods have a
            derivation (`CanonicalPeriod.derivation`) instead. See LINEAGE.
        raw_locator:
          type: string
        farm:
          type: string
          format: uuid
          description: ID of the Organization that is a Farm. For reported periods, the farm of the feed; for computed
            periods, the farm of the resolved events they come from. Key of partitioning, row-level access and erasure;
            see STORAGE. Only for `period_type` = withdrawal; causing treatment is `start_event` or a derivation
            input.
      required:
      - id
      - period_type
      - period
      - status
      - source_producer
      - revision
      - created_at
      - updated_at
      - subject
      - farm
    AnimalPeriod:
      allOf:
      - $ref: '#/components/schemas/CanonicalPeriod'
      - type: object
        properties:
          animal:
            type: string
            format: uuid
            description: ID of the Animal.
        required:
        - animal
      description: A CanonicalPeriod whose subject is AnimalPeriod.
    AnimalGroupPeriod:
      allOf:
      - $ref: '#/components/schemas/CanonicalPeriod'
      - type: object
        properties:
          animal_group:
            type: string
            format: uuid
            description: ID of the AnimalGroup.
        required:
        - animal_group
      description: A CanonicalPeriod whose subject is AnimalGroupPeriod.
    PeriodType:
      description: Catalog of the kinds of period, such as lactation, dry, pregnancy and withdrawal, scoped to species.
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Key.
        code:
          type: string
          description: 'Unique. Initial values: lactation, dry, pregnancy, withdrawal, `laying_cycle`, fattening.'
        name:
          type: string
        applies_to:
          type: array
          items:
            type: string
            format: uuid
          minItems: 1
          description: ID of the AnimalType.
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
      - id
      - code
      - name
      - applies_to
      - created_at
      - updated_at
    FarmConfiguration:
      description: Farm context that changes over time and affects how data is read and exported, such as the milking
        system in use.
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: Key.
        farm:
          type: string
          format: uuid
          description: ID of the Organization that is a Farm.
        period:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/Period
        milking_system:
          type: string
          enum:
          - robot
          - parlour_2x
          - parlour_3x
          - other
          - none
          description: Drives the official CG-CELL regularity code.
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
      required:
      - id
      - farm
      - period
      - milking_system
      - created_at
      - updated_at
    EventLineage:
      type: object
      description: From a canonical record back to its raw data, its source and the write that made it available,
        with stored references only.
      properties:
        raw_metadata:
          type: string
          format: uuid
          description: ID of the RawMetadata (Files API).
        raw_locator:
          type: string
        source_record_key:
          type: string
        source_producer:
          type: string
          format: uuid
          description: ID of the SourceProducerEntity (Sources API, lineage).
        source_feed:
          type: string
          format: uuid
        device:
          type: string
          format: uuid
        available_in:
          type: integer
          description: The write number (WriteCommit.seq) of this revision.
        replaced_in:
          type: integer
        write_commit:
          type: object
          additionalProperties: true
          description: The WriteCommit, as in the Versioning API.
        derivation:
          type: string
          format: uuid
          description: ID of the CanonicalDerivation, for records we compute.
      required:
      - source_producer
      - source_feed
      - available_in
    OffspringInput:
      type: object
      description: Input to create or change a Offspring; server-managed fields are left out.
      properties:
        animal:
          type: string
          format: uuid
          description: ID of the Animal. The registered animal, when the newborn was registered.
        sex:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/AnimalSexEnum
        viability:
          type: string
          enum:
          - alive
          - stillborn
          - died_after_birth
          - unknown
      required:
      - viability
      additionalProperties: false
    TreatmentProductInput:
      type: object
      description: Input to create or change a TreatmentProduct; server-managed fields are left out.
      properties:
        product_code:
          type: string
          description: Official medicine code when known (e.g. the Italian AIC code).
        product_name:
          type: string
        dose:
          type: number
        dose_unit:
          type: string
          description: UCUM or a package unit (tube, dose, piece).
        dose_basis:
          type: string
          enum:
          - per_animal
          - per_100kg_bodyweight
          - per_quarter
          - total
          - unknown
          default: unknown
          description: e.g. "20 ML / 100 Kg" = dose 20, unit mL, basis `per_100kg_bodyweight`; "1 TUBO X QUARTO"
            = `per_quarter`.
        total_quantity:
          type: number
          description: Total quantity unloaded from stock for this treatment, in `dose_unit`.
        route:
          type: string
          enum:
          - injection
          - oral
          - intramammary
          - topical
          - intrauterine
          - other
          - unknown
        withdrawals:
          type: array
          items:
            $ref: ../../../../common/v1/schemas.yaml#/components/schemas/WithdrawalSpec
      required:
      - product_name
      - dose_basis
      - route
      additionalProperties: false
    EventEntry:
      type: object
      description: An event recorded by an operator in the app. It is stored as a raw file of the Organization's
        MoonitoringAppChannel feed and parsed into a CanonicalEvent with an operator origin; the typed fields apply
        according to `type`.
      properties:
        animal:
          type: string
          format: uuid
          description: The animal, for an animal event.
        animal_group:
          type: string
          format: uuid
          description: The group, for a group event.
        type:
          type: string
          enum:
          - HerdEntryEvent
          - HerdExitEvent
          - ServiceEvent
          - PregnancyCheckEvent
          - ParturitionEvent
          - AbortionEvent
          - DryOffEvent
          - HeatEvent
          - DiagnosisEvent
          - TreatmentEvent
          - HealthCheckEvent
          - BreedingStatusEvent
          - GroupTreatmentEvent
          description: Which event this is; the typed fields that apply are those of the subtype in the data model.
        occurred:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/EventTime
        note:
          type: string
        entry_reason:
          type: string
          enum:
          - purchase
          - transfer_in
          - other
          - unknown
        exit_type:
          type: string
          enum:
          - sale_alive
          - transfer_out
          - sent_to_slaughter
          - emergency_slaughter
          - slaughter_confirmed
          - death
          - other
          - unknown
          description: 'Map each country''s export explicitly; dispatch to slaughter does not prove confirmed slaughter.
            `emergency_slaughter`: slaughter of an injured or sick animal under the veterinary emergency rules (in
            Italy code 5). A source code may change meaning by farm and period (e.g. one farm records planned culls
            as transfers since 2018; code 5 rules changed in 2022 and 2026): parser mappings can be scoped by farm
            and validity period, and `source_code` is kept so the mapping can be re-applied.'
        death_type:
          type: string
          format: uuid
          description: ID of the DeathType. Only when `exit_type` = death.
        cause:
          type: string
        destination:
          type: string
        management_episode:
          type: string
          format: uuid
          description: ID of the Ownership that is a AnimalOwnership.
        exited_group:
          type: string
          format: uuid
          description: ID of the AnimalGroup.
        service_method:
          type: string
          enum:
          - artificial_insemination
          - natural_service
          - embryo_transfer
          - unknown
        sire:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/ParentReference
        semen_type:
          type: string
          enum:
          - conventional
          - sexed_female
          - sexed_male
          - unknown
          default: unknown
          description: Sexed semen of both sexes is sold (SiAlleva `Sex Fem`, `Sex Msc`).
        embryo_donor:
          allOf:
          - $ref: ../../../../common/v1/schemas.yaml#/components/schemas/ParentReference
          description: 'Only for `embryo_transfer`: the genetic mother. The animal of the event is the recipient.'
        reported_outcome:
          allOf:
          - $ref: ../../../../common/v1/schemas.yaml#/components/schemas/CodedValue
          description: Known at this revision's availability, not a new examination without evidence.
        result:
          type: string
          enum:
          - pregnant
          - not_pregnant
          - uncertain
        related_service:
          type: string
          format: uuid
          description: ID of the CanonicalEvent that is a ServiceEvent.
        calving_ease:
          allOf:
          - $ref: ../../../../common/v1/schemas.yaml#/components/schemas/CodedValue
          description: Code plus code system, e.g. ICAR, PRES A-E, Lely BreCode.
        offspring:
          type: array
          items:
            $ref: '#/components/schemas/OffspringInput'
          description: 'ParturitionEvent: one row per newborn, alive or dead.'
        detection:
          type: string
          enum:
          - visual
          - sensor_alert
          - unknown
        condition:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/CodedValue
        body_site:
          type: string
          format: uuid
          description: ID of the BodySite.
        supporting_observations:
          type: array
          items:
            type: string
            format: uuid
          description: ID of the CanonicalObservation. Observations used as evidence, e.g. a lab SCC. The diagnosis
            points to them, not the opposite.
        treatment_kind:
          type: string
          enum:
          - drug
          - vaccination
          - procedure
          - reproductive_protocol
        related_diagnosis:
          type: string
          format: uuid
          description: ID of the CanonicalEvent that is a DiagnosisEvent.
        ends_at:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/EventTime
        products:
          type: array
          items:
            $ref: '#/components/schemas/TreatmentProductInput'
          description: TreatmentEvent and GroupTreatmentEvent.
        finding:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/CodedValue
      required:
      - type
      - occurred
      additionalProperties: false
    CancellationRequest:
      type: object
      description: Appends a cancellation revision.
      properties:
        reason:
          type: string
      required:
      - reason
    EventCorrectionRequest:
      type: object
      description: Appends a corrected revision to an event that entered through the Organization's own feeds; the
        fields given replace those of the current revision.
      properties:
        occurred:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/EventTime
        fields:
          type: object
          additionalProperties: true
          description: Typed fields of the event's subtype.
        reason:
          type: string
      required:
      - reason
    PeriodTypeInput:
      type: object
      description: Input to create or change a PeriodType; server-managed fields are left out.
      properties:
        code:
          type: string
          description: 'Unique. Initial values: lactation, dry, pregnancy, withdrawal, `laying_cycle`, fattening.'
        name:
          type: string
        applies_to:
          type: array
          items:
            type: string
            format: uuid
          minItems: 1
          description: ID of the AnimalType.
      required:
      - code
      - name
      - applies_to
      additionalProperties: false
    DeathTypeInput:
      type: object
      description: Input to create or change a DeathType; server-managed fields are left out.
      properties:
        name:
          type: string
          description: Unique.
      required:
      - name
      additionalProperties: false
    FarmConfigurationInput:
      type: object
      description: Input to create or change a FarmConfiguration; server-managed fields are left out.
      properties:
        period:
          $ref: ../../../../common/v1/schemas.yaml#/components/schemas/Period
        milking_system:
          type: string
          enum:
          - robot
          - parlour_2x
          - parlour_3x
          - other
          - none
          description: Drives the official CG-CELL regularity code.
      required:
      - period
      - milking_system
      additionalProperties: false
  securitySchemes:
    bearer:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: 'The short-lived token signed by `access`: an Organization user token, a staff token or a client
        token, as the operation''s audience says.'
