{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "specs/139-verify-access-permissions-assist/contracts/verification-assist.view-model.json",
  "title": "Verification Assist View Model",
  "type": "object",
  "required": [
    "tenant",
    "verification",
    "overview",
    "missing_permissions",
    "copy",
    "actions",
    "fallback"
  ],
  "properties": {
    "tenant": {
      "type": "object",
      "required": ["id", "external_id", "name"],
      "properties": {
        "id": { "type": "integer", "minimum": 1 },
        "external_id": { "type": "string", "minLength": 1 },
        "name": { "type": "string", "minLength": 1 }
      },
      "additionalProperties": false
    },
    "verification": {
      "type": "object",
      "required": ["overall", "status", "is_stale", "stale_reason"],
      "properties": {
        "overall": { "type": ["string", "null"] },
        "status": { "type": ["string", "null"] },
        "is_stale": { "type": "boolean" },
        "stale_reason": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    },
    "overview": {
      "type": "object",
      "required": ["overall", "counts", "freshness"],
      "properties": {
        "overall": {
          "type": "string",
          "enum": ["ready", "needs_attention", "blocked"]
        },
        "counts": {
          "type": "object",
          "required": ["missing_application", "missing_delegated", "present", "error"],
          "properties": {
            "missing_application": { "type": "integer", "minimum": 0 },
            "missing_delegated": { "type": "integer", "minimum": 0 },
            "present": { "type": "integer", "minimum": 0 },
            "error": { "type": "integer", "minimum": 0 }
          },
          "additionalProperties": false
        },
        "freshness": {
          "type": "object",
          "required": ["last_refreshed_at", "is_stale"],
          "properties": {
            "last_refreshed_at": { "type": ["string", "null"] },
            "is_stale": { "type": "boolean" }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "missing_permissions": {
      "type": "object",
      "required": ["application", "delegated"],
      "properties": {
        "application": {
          "type": "array",
          "items": { "$ref": "#/$defs/permissionRow" }
        },
        "delegated": {
          "type": "array",
          "items": { "$ref": "#/$defs/permissionRow" }
        }
      },
      "additionalProperties": false
    },
    "copy": {
      "type": "object",
      "required": ["application", "delegated"],
      "properties": {
        "application": { "type": "string" },
        "delegated": { "type": "string" }
      },
      "additionalProperties": false
    },
    "actions": {
      "type": "object",
      "required": [
        "full_page",
        "copy_application",
        "copy_delegated",
        "grant_admin_consent",
        "manage_provider_connection",
        "rerun_verification"
      ],
      "properties": {
        "full_page": { "$ref": "#/$defs/linkAction" },
        "copy_application": { "$ref": "#/$defs/copyAction" },
        "copy_delegated": { "$ref": "#/$defs/copyAction" },
        "grant_admin_consent": { "$ref": "#/$defs/linkActionNullable" },
        "manage_provider_connection": { "$ref": "#/$defs/linkActionNullable" },
        "rerun_verification": {
          "type": "object",
          "required": ["label", "handled_by_existing_wizard"],
          "properties": {
            "label": { "type": "string", "minLength": 1 },
            "handled_by_existing_wizard": { "const": true }
          },
          "additionalProperties": false
        }
      },
      "additionalProperties": false
    },
    "fallback": {
      "type": "object",
      "required": ["has_incomplete_detail", "message"],
      "properties": {
        "has_incomplete_detail": { "type": "boolean" },
        "message": { "type": ["string", "null"] }
      },
      "additionalProperties": false
    }
  },
  "$defs": {
    "permissionRow": {
      "type": "object",
      "required": ["key", "type", "description", "features", "status", "details"],
      "properties": {
        "key": { "type": "string", "minLength": 1 },
        "type": { "type": "string", "enum": ["application", "delegated"] },
        "description": { "type": ["string", "null"] },
        "features": {
          "type": "array",
          "items": { "type": "string" }
        },
        "status": { "type": "string", "enum": ["granted", "missing", "error"] },
        "details": { "type": ["object", "null"] }
      },
      "additionalProperties": false
    },
    "linkAction": {
      "type": "object",
      "required": ["label", "url", "opens_in_new_tab", "available"],
      "properties": {
        "label": { "type": "string", "minLength": 1 },
        "url": { "type": "string", "minLength": 1 },
        "opens_in_new_tab": { "type": "boolean" },
        "available": { "type": "boolean" },
        "is_secondary": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "linkActionNullable": {
      "type": "object",
      "required": ["label", "url", "opens_in_new_tab", "available"],
      "properties": {
        "label": { "type": "string", "minLength": 1 },
        "url": { "type": ["string", "null"] },
        "opens_in_new_tab": { "type": "boolean" },
        "available": { "type": "boolean" }
      },
      "additionalProperties": false
    },
    "copyAction": {
      "type": "object",
      "required": ["label", "payload", "available"],
      "properties": {
        "label": { "type": "string", "minLength": 1 },
        "payload": { "type": "string" },
        "available": { "type": "boolean" }
      },
      "additionalProperties": false
    }
  },
  "additionalProperties": false
}