{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://schemas.conservice.com/identity/v1/identity.yaml.schema.json",
  "title": "Conservice Console Keycloak Application Configuration",
  "description": "Schema for defining Keycloak application groups, roles, and teams for Conservice Console AuthX",
  "type": "object",
  "properties": {
    "displayName": {
      "type": "string",
      "description": "Display name for the application. Defaults to the repository name if not set."
    },
    "allowExternalUsers": {
      "type": "boolean",
      "description": "If set to true, external users are allowed to access the application.",
      "default": false
    },
    "roles": {
      "type": "array",
      "description": "List of application-specific roles.",
      "items": {
        "type": "object",
        "properties": {
          "name": {
            "type": "string",
            "description": "Name of the role.",
            "pattern": "^[A-Za-z][A-Za-z0-9_-]*$",
            "examples": ["Administrator", "Editor", "Viewer"]
          },
          "displayName": {
            "type": "string",
            "description": "Display name for the role. Defaults to the role name if not set."
          },
          "displayOrder": {
            "type": "integer",
            "description": "Display order for the role in the UI.",
            "minimum": 1
          }
        },
        "required": ["name"],
        "additionalProperties": false
      }
    },
    "taskServiceSources": {
      "type": "array",
      "description": "List of task service sources for applications that integrate with Task Service.",
      "items": {
        "type": "string",
        "pattern": "^[A-Za-z][A-Za-z0-9_-]*$"
      },
      "examples": [["TASK_SOURCE_ID", "ANOTHER_SOURCE"]]
    },
    "myAppsCallbackUrl": {
      "type": "string",
      "format": "uri",
      "description": "URL of a service endpoint that returns My Apps menu configuration dynamically. Takes precedence over 'myApps' — if both are defined, 'myApps' is ignored (with a warning). Must use http or https scheme and a hostname that is a subdomain of an approved domain.",
      "examples": ["https://my-app.conservice.com/api/my-apps"]
    },
    "myApps": {
      "type": "object",
      "description": "'My Apps' configuration for the application. Ignored if 'myAppsCallbackUrl' is set.",
      "properties": {
        "path": {
          "type": "string",
          "description": "Path to use for the 'My Apps' link for the application.",
          "examples": ["/application-dashboard", "/app/home"]
        },
        "displayText": {
          "type": "string",
          "description": "Text to display for the 'My Apps' link. Defaults to application display text if not set."
        },
        "subRoutes": {
          "type": "array",
          "description": "Optional sub-navigation links within the application's 'My Apps' entry.",
          "items": {
            "type": "object",
            "properties": {
              "path": {
                "type": "string",
                "description": "The path to use for the sub-route link."
              },
              "displayText": {
                "type": "string",
                "description": "The text to display for the sub-route link."
              },
              "displayOrder": {
                "type": "integer",
                "description": "Deprecated. Sub-routes are rendered in the order declared in the YAML file. This field is accepted but ignored."
              },
              "permittedRoles": {
                "type": "array",
                "description": "List of roles that are permitted to access the sub-route.",
                "items": {
                  "type": "string",
                  "pattern": "^[A-Za-z][A-Za-z0-9_-]*$"
                }
              }
            },
            "required": ["path", "displayText"],
            "additionalProperties": false
          }
        }
      },
      "required": ["path"],
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}
