{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "/schemas/3.0.6/account/sync-governance-request.json",
  "title": "Sync Governance Request",
  "description": "Sync governance agent endpoints against specific accounts. The seller persists these governance agents and calls them for approval during media buy lifecycle events via check_governance. Uses replace semantics: each call replaces any previously synced agents on the specified accounts. The seller MUST verify that the authenticated agent has authority over each referenced account before persisting governance agents.",
  "x-mutates-state": true,
  "type": "object",
  "properties": {
    "adcp_major_version": {
      "type": "integer",
      "description": "The AdCP major version the buyer's payloads conform to. Sellers validate against their supported major_versions and return VERSION_UNSUPPORTED if unsupported. When omitted, the seller assumes its highest supported version.",
      "minimum": 1,
      "maximum": 99
    },
    "idempotency_key": {
      "type": "string",
      "description": "Client-generated unique key for at-most-once execution. `account` gives resource-level dedup, but governance changes emit audit events and can trigger reapproval flows — this key prevents those side effects from firing twice on retry. MUST be unique per (seller, request) pair. Use a fresh UUID v4 for each request.",
      "minLength": 16,
      "maxLength": 255,
      "pattern": "^[A-Za-z0-9_.:-]{16,255}$"
    },
    "accounts": {
      "type": "array",
      "description": "Per-account governance agent configuration. Each entry pairs an account reference with the governance agents for that account.",
      "items": {
        "type": "object",
        "properties": {
          "account": {
            "$ref": "/schemas/3.0.6/core/account-ref.json",
            "description": "Account to sync governance agents for. Use account_id for explicit accounts or brand + operator for implicit accounts."
          },
          "governance_agents": {
            "type": "array",
            "description": "Governance agent endpoints for this account. The seller calls these agents via check_governance during media buy lifecycle events.",
            "items": {
              "type": "object",
              "properties": {
                "url": {
                  "type": "string",
                  "format": "uri",
                  "pattern": "^https://",
                  "description": "Governance agent endpoint URL. Must use HTTPS."
                },
                "authentication": {
                  "type": "object",
                  "description": "Authentication the seller presents when calling this governance agent.",
                  "properties": {
                    "schemes": {
                      "type": "array",
                      "items": {
                        "$ref": "/schemas/3.0.6/enums/auth-scheme.json"
                      },
                      "minItems": 1,
                      "maxItems": 1
                    },
                    "credentials": {
                      "type": "string",
                      "description": "Authentication credential (e.g., Bearer token).",
                      "minLength": 32
                    }
                  },
                  "required": [
                    "schemes",
                    "credentials"
                  ],
                  "additionalProperties": false
                },
                "categories": {
                  "type": "array",
                  "items": {
                    "type": "string",
                    "maxLength": 64,
                    "pattern": "^[a-z][a-z0-9_]*$"
                  },
                  "description": "Governance categories this agent handles (e.g., ['budget_authority', 'strategic_alignment']). When omitted, the agent handles all categories.",
                  "maxItems": 20
                }
              },
              "required": [
                "url",
                "authentication"
              ],
              "additionalProperties": false
            },
            "minItems": 1,
            "maxItems": 10
          }
        },
        "required": [
          "account",
          "governance_agents"
        ],
        "additionalProperties": false
      },
      "minItems": 1,
      "maxItems": 100
    },
    "context": {
      "$ref": "/schemas/3.0.6/core/context.json"
    },
    "ext": {
      "$ref": "/schemas/3.0.6/core/ext.json"
    }
  },
  "required": [
    "idempotency_key",
    "accounts"
  ],
  "additionalProperties": true,
  "examples": [
    {
      "description": "Sync governance agents on explicit accounts (by account_id)",
      "data": {
        "idempotency_key": "e1b3a6c8-5678-489a-bcde-f01234567891",
        "accounts": [
          {
            "account": {
              "account_id": "acct-social-001"
            },
            "governance_agents": [
              {
                "url": "https://governance.pinnacle-media.com/budget",
                "authentication": {
                  "schemes": [
                    "Bearer"
                  ],
                  "credentials": "gov-token-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
                },
                "categories": [
                  "budget_authority"
                ]
              }
            ]
          }
        ]
      }
    },
    {
      "description": "Sync governance agents on implicit accounts (by brand + operator)",
      "data": {
        "idempotency_key": "f2c4b7d9-6789-489b-cdef-012345678902",
        "accounts": [
          {
            "account": {
              "brand": {
                "domain": "nova-brands.com",
                "brand_id": "spark"
              },
              "operator": "pinnacle-media.com"
            },
            "governance_agents": [
              {
                "url": "https://governance.pinnacle-media.com/compliance",
                "authentication": {
                  "schemes": [
                    "Bearer"
                  ],
                  "credentials": "gov-token-yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy"
                },
                "categories": [
                  "geo_compliance"
                ]
              }
            ]
          }
        ]
      }
    }
  ]
}
