{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cotal-ai/json-schema/cotal-ai-service-result-schema.json",
  "title": "ServiceResult",
  "description": "Transport envelope only. Nested native fields and operation-specific constraints are defined by ServiceAuthorityResult in the linked source; this schema is not a complete native command contract.",
  "x-generated": "2026-11-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/cotal-ai-auth-openapi.yml#/components/schemas/ServiceResult",
  "type": "object",
  "properties": {
    "v": {
      "const": 1
    },
    "kind": {
      "const": "service-endpoint-authority"
    },
    "requestId": {
      "type": "string",
      "pattern": "^[0-9a-f]{32}$"
    },
    "space": {
      "type": "string",
      "minLength": 1
    },
    "accountPublicKey": {
      "type": "string",
      "minLength": 1
    },
    "endpoint": {
      "type": "string",
      "minLength": 1
    },
    "instanceId": {
      "type": "string",
      "minLength": 1
    },
    "operation": {
      "type": "string",
      "enum": [
        "register",
        "activate",
        "renew",
        "ready",
        "revoke",
        "status",
        "describe-view"
      ]
    },
    "state": {
      "type": "string",
      "enum": [
        "approval-required",
        "pending",
        "registered",
        "credential",
        "ready",
        "status",
        "retired",
        "view",
        "denied"
      ]
    },
    "reason": {
      "type": "string"
    },
    "witness": {
      "$ref": "#/$defs/ServiceWitness"
    },
    "status": {
      "type": "object",
      "properties": {
        "state": {
          "type": "string",
          "enum": [
            "proposed",
            "approved-unregistered",
            "registering",
            "revoking",
            "registered",
            "ready",
            "retired",
            "refused",
            "superseded"
          ]
        }
      },
      "required": [
        "state"
      ]
    }
  },
  "required": [
    "v",
    "kind",
    "requestId",
    "space",
    "accountPublicKey",
    "endpoint",
    "instanceId",
    "operation",
    "state"
  ],
  "x-native-contract": {
    "name": "ServiceAuthorityResult",
    "url": "https://github.com/Cotal-AI/Cotal/blob/main/packages/core/src/remote-service-authority.ts"
  },
  "allOf": [
    {
      "if": {
        "properties": {
          "state": {
            "const": "denied"
          }
        },
        "required": [
          "state"
        ]
      },
      "then": {
        "required": [
          "reason"
        ]
      }
    }
  ],
  "$defs": {
    "ServiceWitness": {
      "type": "object",
      "properties": {
        "accountPublicKey": {
          "type": "string",
          "minLength": 1
        },
        "space": {
          "type": "string",
          "minLength": 1
        },
        "endpoint": {
          "type": "string",
          "minLength": 1
        },
        "instanceId": {
          "type": "string",
          "minLength": 1
        },
        "principal": {
          "type": "object",
          "properties": {
            "owner": {
              "type": "string",
              "minLength": 1
            },
            "actor": {
              "type": "string",
              "minLength": 1
            },
            "lifecycleUid": {
              "type": "string",
              "minLength": 1
            }
          },
          "required": [
            "owner",
            "actor",
            "lifecycleUid"
          ]
        },
        "rootCredentialId": {
          "type": "string",
          "minLength": 1
        },
        "approvalDigest": {
          "type": "string",
          "minLength": 1
        },
        "processEpoch": {
          "type": "integer",
          "minimum": 0
        },
        "registrationRevision": {
          "type": "integer",
          "minimum": 0
        },
        "nameAuthorityRevision": {
          "type": "integer",
          "minimum": 0
        },
        "registrationRequestId": {
          "type": "string",
          "minLength": 1
        },
        "registrationProof": {
          "type": "string",
          "minLength": 1
        }
      },
      "required": [
        "accountPublicKey",
        "space",
        "endpoint",
        "instanceId",
        "principal",
        "rootCredentialId",
        "approvalDigest",
        "processEpoch",
        "registrationRevision",
        "nameAuthorityRevision",
        "registrationRequestId",
        "registrationProof"
      ],
      "description": "Transport envelope only. Nested native fields and operation-specific constraints are defined by ServiceRegistrationWitness in the linked source; this schema is not a complete native command contract.",
      "x-native-contract": {
        "name": "ServiceRegistrationWitness",
        "url": "https://github.com/Cotal-AI/Cotal/blob/main/packages/core/src/remote-service-authority.ts"
      }
    }
  }
}