{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://id.schemas.pub/o/DTI/DTR/TrustRegistryEntry",
  "title": "Trust Registry Entry Info",
  "description": "Response from the Trust Registry Entry Information API endpoint (GET /api/entry/{id}/)",
  "type": "object",
  "required": [
    "trustLevel",
    "trustStatus",
    "verifiedDomain",
    "trustInfo",
    "serviceInfo",
    "operatorInfo",
    "authConnection",
    "dataConnection",
    "entityDataValidity",
    "entityHtmlUrl"
  ],
  "properties": {
    "trustLevel": {
      "type": "integer",
      "minimum": 0,
      "maximum": 2,
      "description": "Trust level assigned to this entry. Current values are 0, 1, or 2; higher values are inclusive of lower trust level requirements. Additional levels may be introduced."
    },
    "trustStatus": {
      "type": "string",
      "description": "Current verification status. 'verified' for a fully verified service. Additional values such as 'under investigation' or 'warning' may be introduced.",
      "examples": ["verified"]
    },
    "verifiedDomain": {
      "type": "string",
      "format": "hostname",
      "description": "The domain name verified as belonging to the service operator."
    },
    "trustInfo": { "$ref": "#/$defs/TrustInfo" },
    "serviceInfo": { "$ref": "#/$defs/ServiceInfo" },
    "operatorInfo": { "$ref": "#/$defs/OperatorInfo" },
    "authConnection": { "$ref": "#/$defs/AuthConnection" },
    "dataConnection": { "$ref": "#/$defs/DataConnection" },
    "entityDataValidity": { "$ref": "#/$defs/EntityDataValidity" },
    "entityHtmlUrl": {
      "type": "string",
      "format": "uri",
      "description": "URL to a human-readable page for this registry entry."
    },
    "additionalProperties": false
  },
  "$defs": {

    "TrustInfo": {
      "type": "object",
      "description": "Trust-related policy documents and contact information for the service and its operator. May contain additional fields contributed by the entry's trust_info record.",
      "required": ["termsOfService", "dataProtectionOfficer"],
      "properties": {
        "servicePrivacyPolicy": {
          "type": "string",
          "format": "uri",
          "description": "URL to the privacy policy specific to this service. Omitted when not set."
        },
        "operatorPrivacyPolicy": {
          "type": "string",
          "format": "uri",
          "description": "URL to the main privacy policy offered by the operator. Omitted when not set."
        },
        "termsOfService": {
          "type": "array",
          "items": { "type": "string", "format": "uri" },
          "description": "URLs of the operator's terms of service and other policy documents that may affect how user data is used. May include the service privacy policy, operator privacy policy, and/or terms of service."
        },
        "dataProtectionOfficer": { "$ref": "#/$defs/DataProtectionOfficer" }
      },
      "additionalProperties": true
    },

    "DataProtectionOfficer": {
      "type": "object",
      "description": "Contact information for the Data Protection Officer as described by the EU's GDPR. All fields may be null when not provided.",
      "required": ["name", "address", "email"],
      "properties": {
        "name": {
          "type": ["string", "null"],
          "description": "Name of the person or office to address data protection requests to."
        },
        "address": {
          "type": ["string", "null"],
          "description": "Mailing address for data protection correspondence."
        },
        "email": {
          "type": ["string", "null"],
          "format": "email",
          "description": "Email address to reach the Data Protection Officer."
        }
      },
      "additionalProperties": false
    },

    "ServiceInfo": {
      "type": "object",
      "description": "Information about the service.",
      "required": ["serviceName", "serviceCategories", "serviceUrl"],
      "properties": {
        "serviceName": {
          "type": "string",
          "description": "Display name of the service, suitable for user-facing contexts such as authorization prompts or service listings. Not unique across the registry; the combination of operator name and service name is unique."
        },
        "serviceCategories": {
          "type": "array",
          "items": { "type": "string" },
          "description": "Names of categories the service participates in (e.g. photo albums, music playlists). The set of possible categories is not fixed."
        },
        "serviceDescription": {
          "oneOf": [
            {
              "type": "string",
              "description": "A plain text description of the service."
            },
            {
              "type": "object",
              "description": "A language map keyed by BCP 47 language tags (e.g. {\"en\": \"Photos\", \"ja\": \"写真\"}).",
              "additionalProperties": { "type": "string" },
              "minProperties": 1
            }
          ],
          "description": "A description of the service. May be a plain string or a language map keyed by BCP 47 language tags. Omitted when not set."
        },
        "serviceIcon": {
          "type": "string",
          "format": "uri",
          "description": "URL to a logo suitable for display alongside the service name. Omitted when not set."
        },
        "serviceUrl": {
          "type": "string",
          "format": "uri",
          "description": "URL to the most appropriate page for users to learn more about the service."
        }
      },
      "additionalProperties": false
    },

    "OperatorInfo": {
      "type": "object",
      "description": "Information about the organization that operates the service.",
      "required": ["serviceOperatorName", "serviceOperatorUrl"],
      "properties": {
        "serviceOperatorName": {
          "type": "string",
          "description": "Name of the organization responsible for the service."
        },
        "serviceOperatorUrl": {
          "type": "string",
          "format": "uri",
          "description": "URL to the operator's primary web presence."
        },
        "serviceOperatorIcon": {
          "type": "string",
          "format": "uri",
          "description": "URL to an icon representing the operator, suitable for display alongside their name. Omitted when not set."
        },
        "serviceOperatorSecurityIssueReportUrl": {
          "type": "string",
          "format": "uri",
          "description": "URL to a page where security issues can be reported to the operator. Omitted when not set."
        }
      },
      "additionalProperties": false
    },

    "AuthConnection": {
      "description": "OAuth connection parameters for this service. Present with OAuth fields when the service requires external user authentication; otherwise an empty object.",
      "oneOf": [
        {
          "type": "object",
          "description": "Service does not require external user authentication.",
          "maxProperties": 0
        },
        {
          "type": "object",
          "description": "Service requires external user authentication via OAuth.",
          "required": ["oAuthRedirectUrls", "oAuthClientId", "oauth_client_metadata"],
          "properties": {
            "oAuthRedirectUrls": {
              "type": "array",
              "items": { "type": "string", "format": "uri" },
              "description": "Allowed OAuth redirect URIs for this service."
            },
            "oAuthClientId": {
              "type": "string",
              "description": "The client_id to supply in OAuth connection requests to this service."
            },
            "oauth_client_metadata": { "$ref": "#/$defs/OAuthClientMetadata" }
          },
          "additionalProperties": false
        }
      ]
    },

    "OAuthClientMetadata": {
      "type": "object",
      "description": "OAuth 2.0 Dynamic Client Registration Metadata per RFC 7591 (https://www.rfc-editor.org/rfc/rfc7591).",
      "required": ["redirect_uris", "client_name"],
      "properties": {
        "redirect_uris": {
          "type": "array",
          "items": { "type": "string", "format": "uri" },
          "description": "Allowed redirect URIs for the OAuth client."
        },
        "client_name": {
          "type": "string",
          "description": "Human-readable name of the OAuth client."
        },
        "logo_uri": {
          "type": "string",
          "format": "uri",
          "description": "URL to a logo representing the OAuth client. Omitted when not set."
        }
      },
      "additionalProperties": true
    },

    "DataConnection": {
      "description": "API connection details for this service. Present with connection fields when the service accepts incoming data requests; otherwise an empty object.",
      "oneOf": [
        {
          "type": "object",
          "description": "Service does not accept incoming data requests.",
          "maxProperties": 0
        },
        {
          "type": "object",
          "description": "Service accepts incoming data requests via a published API.",
          "required": ["apiConnectionInfo"],
          "properties": {
            "apiConnectionInfo": { "$ref": "#/$defs/ApiConnectionInfo" }
          },
          "additionalProperties": false
        }
      ]
    },

    "ApiConnectionInfo": {
      "type": "object",
      "description": "Details for reaching the service's data API.",
      "required": ["apiRootUrl", "apiDocsUrl"],
      "properties": {
        "apiRootUrl": {
          "type": "string",
          "format": "uri",
          "description": "Root URL of the service's data API."
        },
        "apiDocsUrl": {
          "type": "string",
          "format": "uri",
          "description": "URL to documentation for the service's data API."
        }
      },
      "additionalProperties": false
    },

    "EntityDataValidity": {
      "type": "object",
      "description": "Validity period for this registry entry.",
      "required": ["validFromDT", "validUntilDT"],
      "properties": {
        "validFromDT": {
          "type": ["string", "null"],
          "format": "date-time",
          "description": "RFC 3339 datetime when this registry entry was first approved. Null if not set. Format: YYYY-MM-DDTHH:mm:ss.sssZ"
        },
        "validUntilDT": {
          "type": ["string"],
          "format": "date-time",
          "description": "RFC 3339 datetime until which this registry entry is valid. An entry should not be relied upon after this date. Note: status may change unexpectedly before this date, so this is not a safe cache TTL.  Format: YYYY-MM-DDTHH:mm:ss.sssZ"
        }
      },
      "additionalProperties": false
    }

  }
}
