{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "/schemas/3.1.0-rc.4/account/sync-governance-response.json",
  "title": "Sync Governance Response",
  "description": "Response from governance agent sync. Returns per-account results confirming sync, or operation-level errors on complete failure.",
  "type": "object",
  "allOf": [
    {
      "$ref": "/schemas/3.1.0-rc.4/core/version-envelope.json"
    },
    {
      "$ref": "/schemas/3.1.0-rc.4/core/protocol-envelope.json"
    }
  ],
  "oneOf": [
    {
      "title": "SyncGovernanceSuccess",
      "description": "Sync processed — individual accounts may have errors",
      "type": "object",
      "properties": {
        "accounts": {
          "type": "array",
          "description": "Per-account sync results",
          "items": {
            "type": "object",
            "properties": {
              "account": {
                "$ref": "/schemas/3.1.0-rc.4/core/account-ref.json",
                "description": "Account reference, echoed from request"
              },
              "status": {
                "type": "string",
                "enum": [
                  "synced",
                  "failed"
                ],
                "description": "Sync result. synced: governance agents persisted. failed: could not complete (see errors)."
              },
              "governance_agents": {
                "type": "array",
                "description": "Governance agent now synced on this account. Reflects the persisted state after sync. Exactly one entry; the array shape mirrors the request schema and the one-agent-per-account invariant. See sync_governance request schema.",
                "items": {
                  "type": "object",
                  "properties": {
                    "url": {
                      "type": "string",
                      "format": "uri",
                      "pattern": "^https://",
                      "description": "Governance agent endpoint URL."
                    }
                  },
                  "required": [
                    "url"
                  ],
                  "additionalProperties": false
                },
                "minItems": 1,
                "maxItems": 1
              },
              "errors": {
                "type": "array",
                "description": "Per-account errors (only present when status is 'failed')",
                "items": {
                  "$ref": "/schemas/3.1.0-rc.4/core/error.json"
                }
              }
            },
            "required": [
              "account",
              "status"
            ],
            "additionalProperties": true
          }
        },
        "context": {
          "$ref": "/schemas/3.1.0-rc.4/core/context.json"
        },
        "ext": {
          "$ref": "/schemas/3.1.0-rc.4/core/ext.json"
        }
      },
      "required": [
        "accounts"
      ],
      "additionalProperties": true,
      "not": {
        "required": [
          "errors"
        ]
      }
    },
    {
      "title": "SyncGovernanceError",
      "description": "Operation failed completely, no accounts were processed",
      "type": "object",
      "properties": {
        "errors": {
          "type": "array",
          "description": "Operation-level errors (e.g., authentication failure, service unavailable)",
          "items": {
            "$ref": "/schemas/3.1.0-rc.4/core/error.json"
          },
          "minItems": 1
        },
        "context": {
          "$ref": "/schemas/3.1.0-rc.4/core/context.json"
        },
        "ext": {
          "$ref": "/schemas/3.1.0-rc.4/core/ext.json"
        }
      },
      "required": [
        "errors"
      ],
      "additionalProperties": true,
      "not": {
        "required": [
          "accounts"
        ]
      }
    }
  ],
  "examples": [
    {
      "description": "Governance agents synced on two accounts",
      "data": {
        "status": "completed",
        "accounts": [
          {
            "account": {
              "account_id": "acct-social-001"
            },
            "status": "synced",
            "governance_agents": [
              {
                "url": "https://governance.pinnacle-media.com"
              }
            ]
          },
          {
            "account": {
              "account_id": "acct-social-002"
            },
            "status": "synced",
            "governance_agents": [
              {
                "url": "https://governance.acme-buyer.com"
              }
            ]
          }
        ]
      }
    },
    {
      "description": "Partial failure — one account not found",
      "data": {
        "status": "completed",
        "accounts": [
          {
            "account": {
              "account_id": "acct-social-001"
            },
            "status": "synced",
            "governance_agents": [
              {
                "url": "https://governance.pinnacle-media.com"
              }
            ]
          },
          {
            "account": {
              "account_id": "acct-unknown"
            },
            "status": "failed",
            "errors": [
              {
                "code": "ACCOUNT_NOT_FOUND",
                "message": "Account 'acct-unknown' does not exist or is not accessible to the authenticated agent."
              }
            ]
          }
        ]
      }
    }
  ],
  "properties": {}
}
