# Proposed event contract, version 1 (AsyncAPI 3.0): the events this system publishes, their consumers, payloads and delivery
# guarantees, and the events it consumes. Status: proposal for review, not confirmed design.
asyncapi: 3.0.0
info:
  title: Farm Events
  version: 1.0.0
  description: 'Facts about the canonical data: the clock advancing, animals and ownership, resolved events, data
    issues, coverage, submissions, erasures and dataset exports. Thin payloads: a consumer reads details through
    the APIs at the write number the event carries. Envelope, delivery guarantees and webhook headers: `common/v1/events.yaml`.
    Status: proposal for review, not confirmed design.'
defaultContentType: application/cloudevents+json
servers:
  prod:
    host: pubsub.googleapis.com
    protocol: googlepubsub
    description: Pub/Sub in the project that hosts the system, prod.
  stage:
    host: pubsub.googleapis.com
    protocol: googlepubsub
    description: Pub/Sub in the project that hosts the system, stage.
channels:
  farm.events.v1:
    address: farm.events.v1
    description: Every event farm publishes. Consumers filter by the `ce-type` attribute.
    messages:
      source_feed_connected_v1:
        $ref: '#/components/messages/source_feed_connected_v1'
      source_feed_disconnected_v1:
        $ref: '#/components/messages/source_feed_disconnected_v1'
      sync_client_enrolled_v1:
        $ref: '#/components/messages/sync_client_enrolled_v1'
      sync_client_retired_v1:
        $ref: '#/components/messages/sync_client_retired_v1'
      sync_run_committed_v1:
        $ref: '#/components/messages/sync_run_committed_v1'
      sync_run_failed_v1:
        $ref: '#/components/messages/sync_run_failed_v1'
      raw_file_committed_v1:
        $ref: '#/components/messages/raw_file_committed_v1'
      raw_file_removed_v1:
        $ref: '#/components/messages/raw_file_removed_v1'
      parse_job_finished_v1:
        $ref: '#/components/messages/parse_job_finished_v1'
      entitlement_granted_v1:
        $ref: '#/components/messages/entitlement_granted_v1'
      entitlement_changed_v1:
        $ref: '#/components/messages/entitlement_changed_v1'
      entitlement_revoked_v1:
        $ref: '#/components/messages/entitlement_revoked_v1'
      feature_usage_limit_reached_v1:
        $ref: '#/components/messages/feature_usage_limit_reached_v1'
      write_commit_committed_v1:
        $ref: '#/components/messages/write_commit_committed_v1'
      animal_registered_v1:
        $ref: '#/components/messages/animal_registered_v1'
      animal_merged_v1:
        $ref: '#/components/messages/animal_merged_v1'
      ownership_transferred_v1:
        $ref: '#/components/messages/ownership_transferred_v1'
      resolved_event_published_v1:
        $ref: '#/components/messages/resolved_event_published_v1'
      data_issue_opened_v1:
        $ref: '#/components/messages/data_issue_opened_v1'
      data_issue_closed_v1:
        $ref: '#/components/messages/data_issue_closed_v1'
      feed_coverage_updated_v1:
        $ref: '#/components/messages/feed_coverage_updated_v1'
      official_submission_sent_v1:
        $ref: '#/components/messages/official_submission_sent_v1'
      official_submission_outdated_v1:
        $ref: '#/components/messages/official_submission_outdated_v1'
      erasure_request_created_v1:
        $ref: '#/components/messages/erasure_request_created_v1'
      erasure_request_executed_v1:
        $ref: '#/components/messages/erasure_request_executed_v1'
      dataset_export_completed_v1:
        $ref: '#/components/messages/dataset_export_completed_v1'
    bindings:
      googlepubsub:
        messageRetentionDuration: 604800s
        schemaSettings:
          encoding: json
          name: projects/moonitoring-<env>-<project>/schemas/farm.events.v1
  farm.parse-jobs.v1:
    address: farm.parse-jobs.v1
    messages:
      parse_job_requested_v1:
        $ref: '#/components/messages/parse_job_requested_v1'
    description: 'The parser work queue. Ordering key: the feed. Subscription with a dead-letter policy after 5
      attempts for transient failures; permanent failures are not retried.'
    bindings:
      googlepubsub:
        schemaSettings:
          encoding: json
          name: projects/moonitoring-<env>-<project>/schemas/farm.parse-jobs.v1
        messageRetentionDuration: 604800s
        messageStoragePolicy:
          allowedPersistenceRegions:
          - europe-west8
  farm.parse-jobs.dead.v1:
    address: farm.parse-jobs.dead.v1
    messages:
      parse_job_dead_v1:
        $ref: '#/components/messages/parse_job_dead_v1'
    description: Jobs that exhausted their attempts, read by the Console.
    bindings:
      googlepubsub:
        schemaSettings:
          encoding: json
          name: projects/moonitoring-<env>-<project>/schemas/farm.parse-jobs.dead.v1
        messageRetentionDuration: 2592000s
operations:
  publish_source_feed_connected_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/source_feed_connected_v1'
    summary: A feed was connected to a farm.
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '44'
  publish_source_feed_disconnected_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/source_feed_disconnected_v1'
    summary: A feed's validity was closed.
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '44.5'
  publish_sync_client_enrolled_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/sync_client_enrolled_v1'
    summary: 'A sync client redeemed an enrolment code: first setup or a reinstallation.'
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - releases
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '67'
    - '67.2'
  publish_sync_client_retired_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/sync_client_retired_v1'
    summary: A farm stopped using a sync client.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - releases
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '67.4'
  publish_sync_run_committed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/sync_run_committed_v1'
    summary: 'A run delivered its files: the SyncRun, its RawMetadata and ParseJobs were recorded in one transaction.'
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '52'
    - '30'
    - '51'
  publish_sync_run_failed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/sync_run_failed_v1'
    summary: A run failed on the client's side, reported at once or deferred to the next contact.
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '52.21'
    - '52.22'
    - '52.24'
  publish_raw_file_committed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/raw_file_committed_v1'
    summary: A new raw file is in the bucket and recorded.
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '30'
  publish_raw_file_removed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/raw_file_removed_v1'
    summary: An uploaded file was removed by its Organization; every record parsed from it was cancelled.
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '30.7'
    - '1002.20'
  publish_parse_job_requested_v1:
    action: send
    channel:
      $ref: '#/channels/farm.parse-jobs.v1'
    messages:
    - $ref: '#/channels/farm.parse-jobs.v1/messages/parse_job_requested_v1'
    summary: 'A parse job is queued. The work queue of the parser workers: one message per job, ordered by feed
      so the files of one feed are parsed in order and all feeds in parallel. Delivered at least once; the job id
      and lease make a second delivery harmless.'
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - farm
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '51'
    - '51.7'
    - '51.9'
    x-moonitoring-ordering-key: feed
  publish_parse_job_finished_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/parse_job_finished_v1'
    summary: 'A parse job ended: done, or failed with its class. A failed job never changes its run''s delivery
      status.'
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '51.4'
    - '51.13'
  publish_parse_job_dead_v1:
    action: send
    channel:
      $ref: '#/channels/farm.parse-jobs.dead.v1'
    messages:
    - $ref: '#/channels/farm.parse-jobs.dead.v1/messages/parse_job_dead_v1'
    summary: A job exhausted its attempts and waits for a person; the other feeds keep flowing.
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '51.13'
  publish_entitlement_granted_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/entitlement_granted_v1'
    summary: An Organization received a feature.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    - grant
    - releases
    - ai-model-platform
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '68'
    - '1006.24'
  publish_entitlement_changed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/entitlement_changed_v1'
    summary: An entitlement's validity or limits changed.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    - grant
    - releases
    - ai-model-platform
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '68.4'
    - '68.7'
  publish_entitlement_revoked_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/entitlement_revoked_v1'
    summary: An entitlement ended.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    - grant
    - releases
    - ai-model-platform
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '68.4'
  publish_feature_usage_limit_reached_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/feature_usage_limit_reached_v1'
    summary: A metered feature reached a limit of its period for an Organization.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    - grant
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '69'
    - '68.7'
  publish_write_commit_committed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/write_commit_committed_v1'
    summary: A write was committed; the watermark may have advanced. Carries the kind of write and what it came
      from, so a consumer knows which farm's data changed.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - ai-model-platform
    - moochat
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '61'
    - '61.3'
  publish_animal_registered_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/animal_registered_v1'
    summary: A new animal record exists, from a feed or the app.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '10'
    - '15'
  publish_animal_merged_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/animal_merged_v1'
    summary: Two animal records were found to be the same animal; readers follow the survivor. Also published when
      a link is reverted.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    - ai-model-platform
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '47'
    - '47.5'
  publish_ownership_transferred_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/ownership_transferred_v1'
    summary: An animal or group changed legal owner or manager farm; who can see it changed.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '16'
    - '1002.10'
  publish_resolved_event_published_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/resolved_event_published_v1'
    summary: 'A resolved fact was created, revised, cancelled or retired: the calving, service, exit or other event
      consumers react to. `event_type` says which; `calving.registered` of the interface guidelines is this event
      with event_type ParturitionEvent.'
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    - ai-model-platform
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '45'
    - '45.5'
    - '45.9'
  publish_data_issue_opened_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/data_issue_opened_v1'
    summary: The system found a doubt, a conflict or a blocked publication and tells the farm what to fix at the
      source.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '48'
    - '48.3'
    - '48.4'
    - '48.7'
  publish_data_issue_closed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/data_issue_closed_v1'
    summary: A data issue was resolved at the source or became obsolete.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '48.5'
    - '48.12'
  publish_feed_coverage_updated_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/feed_coverage_updated_v1'
    summary: After a sync, how far a feed's data is present, complete and settled, per kind of data.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - ai-model-platform
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '66'
  publish_official_submission_sent_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/official_submission_sent_v1'
    summary: A submission left for an official body.
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '60'
    - '60.8'
  publish_official_submission_outdated_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/official_submission_outdated_v1'
    summary: Something a sent submission included changed or was cancelled at the source.
    x-moonitoring-producer: farm
    x-moonitoring-consumers: []
    x-moonitoring-webhook: true
    x-moonitoring-requirements:
    - '60.12'
  publish_erasure_request_created_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/erasure_request_created_v1'
    summary: A farm asked for its data to be removed.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    - ai-model-platform
    - grant
    - releases
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '63'
  publish_erasure_request_executed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/erasure_request_executed_v1'
    summary: A farm's data was anonymized; every system that holds something that leads back to it does the same.
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - moochat
    - ai-model-platform
    - grant
    - releases
    - access
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '63.4'
    - '63.5'
  publish_dataset_export_completed_v1:
    action: send
    channel:
      $ref: '#/channels/farm.events.v1'
    messages:
    - $ref: '#/channels/farm.events.v1/messages/dataset_export_completed_v1'
    summary: 'A dataset export finished: the files and manifest are in the datasets bucket.'
    x-moonitoring-producer: farm
    x-moonitoring-consumers:
    - ai-model-platform
    x-moonitoring-webhook: false
    x-moonitoring-requirements:
    - '72'
    - '73'
components:
  messages:
    source_feed_connected_v1:
      name: source_feed.connected.v1
      title: source_feed.connected.v1
      summary: A feed was connected to a farm.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: source_feed.connected.v1
            subject:
              type: string
              description: The feed id.
            data:
              $ref: '#/components/schemas/SourceFeedConnectedV1Data'
    source_feed_disconnected_v1:
      name: source_feed.disconnected.v1
      title: source_feed.disconnected.v1
      summary: A feed's validity was closed.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: source_feed.disconnected.v1
            subject:
              type: string
              description: The feed id.
            data:
              $ref: '#/components/schemas/SourceFeedDisconnectedV1Data'
    sync_client_enrolled_v1:
      name: sync_client.enrolled.v1
      title: sync_client.enrolled.v1
      summary: 'A sync client redeemed an enrolment code: first setup or a reinstallation.'
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: sync_client.enrolled.v1
            subject:
              type: string
              description: The sync client id.
            data:
              $ref: '#/components/schemas/SyncClientEnrolledV1Data'
    sync_client_retired_v1:
      name: sync_client.retired.v1
      title: sync_client.retired.v1
      summary: A farm stopped using a sync client.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: sync_client.retired.v1
            subject:
              type: string
              description: The sync client id.
            data:
              $ref: '#/components/schemas/SyncClientRetiredV1Data'
    sync_run_committed_v1:
      name: sync_run.committed.v1
      title: sync_run.committed.v1
      summary: 'A run delivered its files: the SyncRun, its RawMetadata and ParseJobs were recorded in one transaction.'
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: sync_run.committed.v1
            subject:
              type: string
              description: The sync run id.
            data:
              $ref: '#/components/schemas/SyncRunCommittedV1Data'
    sync_run_failed_v1:
      name: sync_run.failed.v1
      title: sync_run.failed.v1
      summary: A run failed on the client's side, reported at once or deferred to the next contact.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: sync_run.failed.v1
            subject:
              type: string
              description: The sync run id.
            data:
              $ref: '#/components/schemas/SyncRunFailedV1Data'
    raw_file_committed_v1:
      name: raw_file.committed.v1
      title: raw_file.committed.v1
      summary: A new raw file is in the bucket and recorded.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: raw_file.committed.v1
            subject:
              type: string
              description: The raw file id.
            data:
              $ref: '#/components/schemas/RawFileCommittedV1Data'
    raw_file_removed_v1:
      name: raw_file.removed.v1
      title: raw_file.removed.v1
      summary: An uploaded file was removed by its Organization; every record parsed from it was cancelled.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: raw_file.removed.v1
            subject:
              type: string
              description: The raw file id.
            data:
              $ref: '#/components/schemas/RawFileRemovedV1Data'
    parse_job_requested_v1:
      name: parse_job.requested.v1
      title: parse_job.requested.v1
      summary: 'A parse job is queued. The work queue of the parser workers: one message per job, ordered by feed
        so the files of one feed are parsed in order and all feeds in parallel. Delivered at least once; the job
        id and lease make a second delivery harmless.'
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: parse_job.requested.v1
            subject:
              type: string
              description: The parse job id.
            data:
              $ref: '#/components/schemas/ParseJobRequestedV1Data'
    parse_job_finished_v1:
      name: parse_job.finished.v1
      title: parse_job.finished.v1
      summary: 'A parse job ended: done, or failed with its class. A failed job never changes its run''s delivery
        status.'
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: parse_job.finished.v1
            subject:
              type: string
              description: The parse job id.
            data:
              $ref: '#/components/schemas/ParseJobFinishedV1Data'
    parse_job_dead_v1:
      name: parse_job.dead.v1
      title: parse_job.dead.v1
      summary: A job exhausted its attempts and waits for a person; the other feeds keep flowing.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: parse_job.dead.v1
            subject:
              type: string
              description: The parse job id.
            data:
              $ref: '#/components/schemas/ParseJobDeadV1Data'
    entitlement_granted_v1:
      name: entitlement.granted.v1
      title: entitlement.granted.v1
      summary: An Organization received a feature.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: entitlement.granted.v1
            subject:
              type: string
              description: The entitlement id.
            data:
              $ref: '#/components/schemas/EntitlementGrantedV1Data'
    entitlement_changed_v1:
      name: entitlement.changed.v1
      title: entitlement.changed.v1
      summary: An entitlement's validity or limits changed.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: entitlement.changed.v1
            subject:
              type: string
              description: The entitlement id.
            data:
              $ref: '#/components/schemas/EntitlementChangedV1Data'
    entitlement_revoked_v1:
      name: entitlement.revoked.v1
      title: entitlement.revoked.v1
      summary: An entitlement ended.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: entitlement.revoked.v1
            subject:
              type: string
              description: The entitlement id.
            data:
              $ref: '#/components/schemas/EntitlementRevokedV1Data'
    feature_usage_limit_reached_v1:
      name: feature_usage.limit_reached.v1
      title: feature_usage.limit_reached.v1
      summary: A metered feature reached a limit of its period for an Organization.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: feature_usage.limit_reached.v1
            subject:
              type: string
              description: The Organization id.
            data:
              $ref: '#/components/schemas/FeatureUsageLimitReachedV1Data'
    write_commit_committed_v1:
      name: write_commit.committed.v1
      title: write_commit.committed.v1
      summary: A write was committed; the watermark may have advanced. Carries the kind of write and what it came
        from, so a consumer knows which farm's data changed.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: write_commit.committed.v1
            subject:
              type: string
              description: The write number.
            data:
              $ref: '#/components/schemas/WriteCommitCommittedV1Data'
    animal_registered_v1:
      name: animal.registered.v1
      title: animal.registered.v1
      summary: A new animal record exists, from a feed or the app.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: animal.registered.v1
            subject:
              type: string
              description: The animal id.
            data:
              $ref: '#/components/schemas/AnimalRegisteredV1Data'
    animal_merged_v1:
      name: animal.merged.v1
      title: animal.merged.v1
      summary: Two animal records were found to be the same animal; readers follow the survivor. Also published
        when a link is reverted.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: animal.merged.v1
            subject:
              type: string
              description: The link id.
            data:
              $ref: '#/components/schemas/AnimalMergedV1Data'
    ownership_transferred_v1:
      name: ownership.transferred.v1
      title: ownership.transferred.v1
      summary: An animal or group changed legal owner or manager farm; who can see it changed.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: ownership.transferred.v1
            subject:
              type: string
              description: The ownership id.
            data:
              $ref: '#/components/schemas/OwnershipTransferredV1Data'
    resolved_event_published_v1:
      name: resolved_event.published.v1
      title: resolved_event.published.v1
      summary: 'A resolved fact was created, revised, cancelled or retired: the calving, service, exit or other
        event consumers react to. `event_type` says which; `calving.registered` of the interface guidelines is this
        event with event_type ParturitionEvent.'
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: resolved_event.published.v1
            subject:
              type: string
              description: The resolved event's logical record id.
            data:
              $ref: '#/components/schemas/ResolvedEventPublishedV1Data'
    data_issue_opened_v1:
      name: data_issue.opened.v1
      title: data_issue.opened.v1
      summary: The system found a doubt, a conflict or a blocked publication and tells the farm what to fix at the
        source.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: data_issue.opened.v1
            subject:
              type: string
              description: The issue id.
            data:
              $ref: '#/components/schemas/DataIssueOpenedV1Data'
    data_issue_closed_v1:
      name: data_issue.closed.v1
      title: data_issue.closed.v1
      summary: A data issue was resolved at the source or became obsolete.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: data_issue.closed.v1
            subject:
              type: string
              description: The issue id.
            data:
              $ref: '#/components/schemas/DataIssueClosedV1Data'
    feed_coverage_updated_v1:
      name: feed_coverage.updated.v1
      title: feed_coverage.updated.v1
      summary: After a sync, how far a feed's data is present, complete and settled, per kind of data.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: feed_coverage.updated.v1
            subject:
              type: string
              description: The feed id.
            data:
              $ref: '#/components/schemas/FeedCoverageUpdatedV1Data'
    official_submission_sent_v1:
      name: official_submission.sent.v1
      title: official_submission.sent.v1
      summary: A submission left for an official body.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: official_submission.sent.v1
            subject:
              type: string
              description: The submission id.
            data:
              $ref: '#/components/schemas/OfficialSubmissionSentV1Data'
    official_submission_outdated_v1:
      name: official_submission.outdated.v1
      title: official_submission.outdated.v1
      summary: Something a sent submission included changed or was cancelled at the source.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: official_submission.outdated.v1
            subject:
              type: string
              description: The submission id.
            data:
              $ref: '#/components/schemas/OfficialSubmissionOutdatedV1Data'
    erasure_request_created_v1:
      name: erasure_request.created.v1
      title: erasure_request.created.v1
      summary: A farm asked for its data to be removed.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: erasure_request.created.v1
            subject:
              type: string
              description: The request id.
            data:
              $ref: '#/components/schemas/ErasureRequestCreatedV1Data'
    erasure_request_executed_v1:
      name: erasure_request.executed.v1
      title: erasure_request.executed.v1
      summary: A farm's data was anonymized; every system that holds something that leads back to it does the same.
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: erasure_request.executed.v1
            subject:
              type: string
              description: The request id.
            data:
              $ref: '#/components/schemas/ErasureRequestExecutedV1Data'
    dataset_export_completed_v1:
      name: dataset_export.completed.v1
      title: dataset_export.completed.v1
      summary: 'A dataset export finished: the files and manifest are in the datasets bucket.'
      traits:
      - $ref: ../../../common/v1/events.yaml#/components/messageTraits/Event
      payload:
        allOf:
        - $ref: ../../../common/v1/events.yaml#/components/schemas/EventEnvelope
        - type: object
          properties:
            type:
              type: string
              const: dataset_export.completed.v1
            subject:
              type: string
              description: The export id.
            data:
              $ref: '#/components/schemas/DatasetExportCompletedV1Data'
  schemas:
    SourceFeedConnectedV1Data:
      type: object
      properties:
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        channel:
          type: string
          format: uuid
        name:
          type: string
        sync_client:
          type: string
          format: uuid
      required:
      - feed
      - farm
      - channel
      - name
    SourceFeedDisconnectedV1Data:
      type: object
      properties:
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        valid_until:
          type: string
          format: date-time
      required:
      - feed
      - farm
      - valid_until
    SyncClientEnrolledV1Data:
      type: object
      properties:
        sync_client:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        service_account:
          type: string
          format: uuid
        installation:
          type: string
          format: uuid
        reinstall:
          type: boolean
      required:
      - sync_client
      - farm
      - service_account
      - reinstall
    SyncClientRetiredV1Data:
      type: object
      properties:
        sync_client:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
      required:
      - sync_client
      - farm
    SyncRunCommittedV1Data:
      type: object
      properties:
        sync_run:
          type: string
          format: uuid
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        kind:
          type: string
          enum:
          - full_snapshot
          - incremental
        coverage_from:
          type: string
          format: date-time
        coverage_until:
          type: string
          format: date-time
        new_raw_files:
          type: array
          items:
            type: string
            format: uuid
        parse_jobs:
          type: array
          items:
            type: string
            format: uuid
        added:
          type: integer
        changed:
          type: integer
        removed:
          type: integer
        unchanged:
          type: integer
      required:
      - sync_run
      - feed
      - farm
      - kind
      - new_raw_files
      - parse_jobs
    SyncRunFailedV1Data:
      type: object
      properties:
        sync_run:
          type: string
          format: uuid
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        failed_step:
          type: string
        failure_class:
          type: string
        last_error:
          type: string
        attempt:
          type: integer
      required:
      - sync_run
      - feed
      - farm
      - failed_step
      - failure_class
      - attempt
    RawFileCommittedV1Data:
      type: object
      properties:
        raw_file:
          type: string
          format: uuid
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        data_hash:
          type: string
        data_size:
          type: integer
        data_path:
          type: string
        sync_run:
          type: string
          format: uuid
      required:
      - raw_file
      - feed
      - farm
      - data_hash
      - data_path
    RawFileRemovedV1Data:
      type: object
      properties:
        raw_file:
          type: string
          format: uuid
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        write_seq:
          type: integer
      required:
      - raw_file
      - feed
      - farm
    ParseJobRequestedV1Data:
      type: object
      properties:
        parse_job:
          type: string
          format: uuid
        raw_file:
          type: string
          format: uuid
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        parser_version:
          type: string
        trigger:
          type: string
          enum:
          - upload
          - parser_change
          - manual
        attempt:
          type: integer
      required:
      - parse_job
      - raw_file
      - feed
      - parser_version
      - trigger
      - attempt
    ParseJobFinishedV1Data:
      type: object
      properties:
        parse_job:
          type: string
          format: uuid
        raw_file:
          type: string
          format: uuid
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        status:
          type: string
          enum:
          - done
          - failed
        failure_class:
          type: string
        write_seq:
          type: integer
          description: The WriteCommit of the canonical revisions, when done.
        skips:
          type: integer
      required:
      - parse_job
      - raw_file
      - feed
      - status
    ParseJobDeadV1Data:
      type: object
      properties:
        parse_job:
          type: string
          format: uuid
        raw_file:
          type: string
          format: uuid
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        failure_class:
          type: string
        last_error:
          type: string
      required:
      - parse_job
      - raw_file
      - feed
      - failure_class
    EntitlementGrantedV1Data:
      type: object
      properties:
        entitlement:
          type: string
          format: uuid
        organization:
          type: string
          format: uuid
        feature:
          type: string
        valid_from:
          type: string
          format: date-time
        valid_until:
          type: string
          format: date-time
        limits:
          type: string
          description: JSON.
      required:
      - entitlement
      - organization
      - feature
    EntitlementChangedV1Data:
      type: object
      properties:
        entitlement:
          type: string
          format: uuid
        organization:
          type: string
          format: uuid
        feature:
          type: string
        valid_until:
          type: string
          format: date-time
        limits:
          type: string
          description: JSON.
      required:
      - entitlement
      - organization
      - feature
    EntitlementRevokedV1Data:
      type: object
      properties:
        entitlement:
          type: string
          format: uuid
        organization:
          type: string
          format: uuid
        feature:
          type: string
        revoked_at:
          type: string
          format: date-time
      required:
      - entitlement
      - organization
      - feature
      - revoked_at
    FeatureUsageLimitReachedV1Data:
      type: object
      properties:
        organization:
          type: string
          format: uuid
        feature:
          type: string
        period:
          type: string
        limit_key:
          type: string
        at_limit:
          type: string
          description: block, degrade or bill.
      required:
      - organization
      - feature
      - period
      - limit_key
    WriteCommitCommittedV1Data:
      type: object
      properties:
        seq:
          type: integer
        kind:
          type: string
          enum:
          - parse
          - sync_diff
          - resolution
          - selection
          - computation
          - identity
          - app_edit
          - file_removal
          - erasure
        farm:
          type: string
          format: uuid
        parse_job:
          type: string
          format: uuid
        sync_run:
          type: string
          format: uuid
        watermark_seq:
          type: integer
        committed_at:
          type: string
          format: date-time
      required:
      - seq
      - kind
      - watermark_seq
      - committed_at
    AnimalRegisteredV1Data:
      type: object
      properties:
        animal:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        animal_type:
          type: string
          format: uuid
        identifiers:
          type: array
          items:
            type: object
            properties:
              type:
                type: string
              value:
                type: string
      required:
      - animal
      - farm
      - animal_type
    AnimalMergedV1Data:
      type: object
      properties:
        link:
          type: string
          format: uuid
        survivor:
          type: string
          format: uuid
        other:
          type: string
          format: uuid
        status:
          type: string
          enum:
          - active
          - reverted
        farm:
          type: string
          format: uuid
      required:
      - link
      - survivor
      - other
      - status
    OwnershipTransferredV1Data:
      type: object
      properties:
        ownership:
          type: string
          format: uuid
        animal:
          type: string
          format: uuid
        animal_group:
          type: string
          format: uuid
        from_manager_farm:
          type: string
          format: uuid
        to_manager_farm:
          type: string
          format: uuid
        to_legal_organization:
          type: string
          format: uuid
        valid_from:
          type: string
          format: date-time
      required:
      - ownership
      - to_manager_farm
      - valid_from
    ResolvedEventPublishedV1Data:
      type: object
      properties:
        resolved_event:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        animal:
          type: string
          format: uuid
        animal_group:
          type: string
          format: uuid
        event_type:
          type: string
          description: e.g. ParturitionEvent.
        occurred:
          type: object
          description: EventTime.
        status:
          type: string
        revision_number:
          type: integer
        write_seq:
          type: integer
      required:
      - resolved_event
      - farm
      - event_type
      - status
      - revision_number
      - write_seq
    DataIssueOpenedV1Data:
      type: object
      properties:
        issue:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        kind:
          type: string
        severity:
          type: string
          enum:
          - high
          - normal
          - low
        decision:
          type: string
        fix_at:
          type: array
          items:
            type: string
            format: uuid
        animals:
          type: array
          items:
            type: string
            format: uuid
        detected_in:
          type: string
          format: uuid
      required:
      - issue
      - farm
      - kind
      - severity
    DataIssueClosedV1Data:
      type: object
      properties:
        issue:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        status:
          type: string
          enum:
          - resolved_at_source
          - obsolete
        closed_in:
          type: string
          format: uuid
      required:
      - issue
      - farm
      - status
    FeedCoverageUpdatedV1Data:
      type: object
      properties:
        feed:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        data_kind:
          type: object
          description: CodedValue.
        data_from:
          type: object
        complete_until:
          type: object
        settled_until:
          type: object
        computed_in:
          type: string
          format: uuid
      required:
      - feed
      - farm
      - data_kind
      - computed_in
    OfficialSubmissionSentV1Data:
      type: object
      properties:
        submission:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        recipient:
          type: string
        format:
          type: string
        coverage_from:
          type: string
          format: date-time
        coverage_until:
          type: string
          format: date-time
        submitted_by:
          type: string
          format: uuid
      required:
      - submission
      - farm
      - recipient
      - format
    OfficialSubmissionOutdatedV1Data:
      type: object
      properties:
        submission:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        issue:
          type: string
          format: uuid
      required:
      - submission
      - farm
      - issue
    ErasureRequestCreatedV1Data:
      type: object
      properties:
        request:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        requested_at:
          type: string
          format: date-time
      required:
      - request
      - farm
      - requested_at
    ErasureRequestExecutedV1Data:
      type: object
      properties:
        request:
          type: string
          format: uuid
        farm:
          type: string
          format: uuid
        executed_in:
          type: integer
        executed_at:
          type: string
          format: date-time
      required:
      - request
      - farm
      - executed_in
      - executed_at
    DatasetExportCompletedV1Data:
      type: object
      properties:
        export:
          type: string
          format: uuid
        status:
          type: string
          enum:
          - ready
          - failed
        data_seq:
          type: integer
        manifest_path:
          type: string
        manifest_hash:
          type: string
        row_count:
          type: integer
        size_bytes:
          type: integer
        error:
          type: string
      required:
      - export
      - status
      - data_seq
x-moonitoring-consumes:
- event: organization.*.v1, membership.*.v1, delegation.*.v1
  producer: access
  why: Keeps its copy of who may act on a farm's feeds and clients.
- event: service_account.registered.v1
  producer: access
  why: Matches the identity minted at enrolment with the sync client.
- event: installation.updated.v1
  producer: releases
  why: Shows the version each sync client runs.
- event: organization.created.v1
  producer: access
  why: Knows the Organizations entitlements can be granted to.
- event: capability catalogs
  producer: every system
  why: Validates the feature of an entitlement, through the Catalog gRPC service.
- event: organization.*.v1, membership.*.v1, delegation.*.v1, organization_role.updated.v1
  producer: access
  why: Keeps its copy of who may read and write which farm's data.
- event: model_version.deployed.v1, model_version.retired.v1
  producer: ai-model-platform
  why: Refreshes the model catalog it shows to Organizations.
- event: farmer_document.read.v1
  producer: grant
  why: Nothing today; a future link between funding checks and farm data (D21).
