{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/inforcer/json-schema/inforcer-tenant-comparison-response-schema.json",
  "title": "tenantComparisonResponse",
  "description": "Response from tenant policy comparison with alignment metrics",
  "x-generated": "2026-12-04",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/inforcer-openapi.json#/components/schemas/tenantComparisonResponse",
  "type": "object",
  "additionalProperties": false,
  "allOf": [
    {
      "$ref": "#/$defs/baseResponseEnvelope"
    },
    {
      "type": "object",
      "properties": {
        "data": {
          "$ref": "#/$defs/tenantComparisonData"
        }
      }
    }
  ],
  "$defs": {
    "acceptedDeviationDetail": {
      "type": "object",
      "description": "Details of an accepted deviation",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": [
            "string",
            "null"
          ],
          "description": "ID of the accepted deviation"
        },
        "acceptedDateTime": {
          "type": "string",
          "format": "date-time",
          "description": "When the deviation was accepted"
        },
        "acceptedByUsername": {
          "type": [
            "string",
            "null"
          ],
          "description": "Username who accepted the deviation"
        },
        "acceptedByUserId": {
          "type": [
            "integer",
            "null"
          ],
          "description": "ID of user who accepted the deviation"
        },
        "acceptedReason": {
          "type": [
            "string",
            "null"
          ],
          "description": "Reason for accepting the deviation"
        },
        "acceptAllChanges": {
          "type": "boolean",
          "description": "Indicates that the deviation applied without individual patch operations"
        },
        "isObsolete": {
          "type": "boolean",
          "description": "Indicates that this accepted deviation was not applied because it is obsolete (policies now align without it)"
        },
        "policyDataDiff": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/patchOperation"
          },
          "description": "Policy JSON patch operations associated with the accepted deviation"
        },
        "policyAssignmentsDiff": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/patchOperation"
          },
          "description": "Assignment JSON patch operations associated with the accepted deviation"
        },
        "validUntil": {
          "type": "string",
          "format": "date-time",
          "description": "(Optional) The date/time until which this deviation is valid"
        },
        "originalBaselineValue": {
          "type": [
            "string",
            "null"
          ],
          "description": "The original baseline value when the deviation was created (stringified JSON). May not reflect current baseline state."
        }
      },
      "required": [
        "acceptedDateTime"
      ]
    },
    "alignmentMetricsData": {
      "type": "object",
      "description": "Calculated alignment statistics",
      "additionalProperties": false,
      "properties": {
        "totalPolicies": {
          "type": "integer",
          "minimum": 0,
          "description": "Total number of policies compared"
        },
        "matchedPolicies": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of exactly matched policies"
        },
        "matchedWithAcceptedDeviations": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of policies matched using accepted deviations"
        },
        "deviatedPolicies": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of policies with unaccepted deviations"
        },
        "recommendedPoliciesFromBaseline": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of policies recommended from baseline that are missing from subject"
        },
        "customerOnlyPolicies": {
          "type": "integer",
          "minimum": 0,
          "description": "Number of policies present only in the customer tenant and not in baseline"
        }
      },
      "required": [
        "totalPolicies",
        "matchedPolicies",
        "matchedWithAcceptedDeviations",
        "deviatedPolicies",
        "recommendedPoliciesFromBaseline",
        "customerOnlyPolicies"
      ]
    },
    "baseResponseEnvelope": {
      "type": "object",
      "description": "The common properties of responses",
      "additionalProperties": false,
      "properties": {
        "success": {
          "type": "boolean",
          "description": "Whether the request was successful"
        },
        "message": {
          "type": [
            "string",
            "null"
          ],
          "description": "An optional message"
        },
        "errors": {
          "type": "array",
          "description": "Any errors that occurred during the request",
          "default": [],
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "success",
        "message",
        "errors"
      ]
    },
    "matchedSubjectPolicy": {
      "type": "object",
      "description": "Information about a single subject policy that matched the baseline policy",
      "additionalProperties": false,
      "properties": {
        "subjectPolicySnapshotId": {
          "type": [
            "string",
            "null"
          ],
          "format": "guid",
          "description": "ID of the subject policy snapshot"
        },
        "subjectPolicySnapshotVersionId": {
          "type": [
            "string",
            "null"
          ],
          "format": "guid",
          "description": "ID of the subject policy snapshot version"
        },
        "subjectPolicyGuid": {
          "type": [
            "string",
            "null"
          ],
          "format": "guid",
          "description": "GUID of the subject policy"
        },
        "policyDataDiff": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/patchOperation"
          },
          "description": "Policy data differences for this specific subject policy"
        },
        "policyAssignmentsDiff": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/patchOperation"
          },
          "description": "Policy assignment differences for this specific subject policy"
        },
        "policyTags": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/policyTag"
          },
          "description": "Policy tags associated with this subject policy"
        },
        "acceptedDeviations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/acceptedDeviationDetail"
          },
          "description": "All accepted deviations for this specific subject policy match, ordered by acceptance date (newest first)"
        }
      },
      "required": [
        "subjectPolicyGuid",
        "policyDataDiff",
        "policyAssignmentsDiff"
      ]
    },
    "patchOperation": {
      "type": "object",
      "description": "A single JSON patch operation",
      "additionalProperties": false,
      "properties": {
        "op": {
          "type": "string",
          "description": "The patch operation type"
        },
        "path": {
          "type": "string",
          "description": "JSON path to the changed property"
        },
        "baselineValue": {
          "type": [
            "string",
            "null"
          ],
          "description": "Value in the baseline policy (stringified JSON)"
        },
        "subjectValue": {
          "type": [
            "string",
            "null"
          ],
          "description": "Value in the subject policy (stringified JSON)"
        }
      },
      "required": [
        "op",
        "path"
      ]
    },
    "policyComparisonDetail": {
      "description": "Detailed information about a single policy comparison result",
      "allOf": [
        {
          "$ref": "#/$defs/policyDetail"
        },
        {
          "type": "object",
          "additionalProperties": false,
          "properties": {
            "baselinePolicySnapshotId": {
              "type": "string",
              "format": "guid",
              "description": "ID of the baseline policy snapshot"
            },
            "baselinePolicySnapshotVersionId": {
              "type": "string",
              "format": "guid",
              "description": "ID of the baseline policy snapshot version"
            },
            "matchingSubjectPolicies": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/matchedSubjectPolicy"
              },
              "description": "All subject policies that matched this baseline policy"
            },
            "isDeviation": {
              "type": "boolean",
              "description": "Whether this represents a policy deviation"
            },
            "isMissingFromSubject": {
              "type": "boolean",
              "description": "Whether this policy is missing from the subject tenant"
            },
            "isAdditionalInSubject": {
              "type": "boolean",
              "description": "Whether this policy is missing from the baseline tenant"
            },
            "matchingVariables": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/variableSubstitutionDetail"
              },
              "description": "Variable substitution details found during policy comparison"
            },
            "similarPolicies": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/similarPolicyResult"
              },
              "description": "Information about similar policies found"
            },
            "acceptedDeviations": {
              "type": "array",
              "items": {
                "$ref": "#/$defs/acceptedDeviationDetail"
              },
              "description": "All accepted deviations for missing policies, ordered by acceptance date (newest first)"
            }
          },
          "required": [
            "matchingSubjectPolicies",
            "isDeviation",
            "isMissingFromSubject",
            "isAdditionalInSubject",
            "matchingVariables"
          ]
        }
      ]
    },
    "policyDetail": {
      "type": "object",
      "description": "Detailed information about a single policy snapshot",
      "additionalProperties": false,
      "properties": {
        "policyGuid": {
          "type": [
            "string",
            "null"
          ],
          "format": "guid",
          "description": "GUID of the policy"
        },
        "policyName": {
          "type": "string",
          "description": "Name of the policy"
        },
        "policySnapshotId": {
          "type": "string",
          "format": "guid",
          "description": "ID of the current policy snapshot"
        },
        "policySnapshotVersionId": {
          "type": "string",
          "format": "guid",
          "description": "ID of the current policy snapshot version"
        },
        "policyTypeId": {
          "type": "integer",
          "description": "Policy type identifier"
        },
        "inforcerPolicyTypeName": {
          "type": "string",
          "description": "Friendly policy type name used in inforcer"
        },
        "policyCategoryId": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Policy category identifier"
        },
        "product": {
          "type": [
            "string",
            "null"
          ],
          "description": "The top-level product from policy category (e.g., Intune, Exchange)"
        },
        "primaryGroup": {
          "type": [
            "string",
            "null"
          ],
          "description": "The primary group from policy category (e.g., Android, iOS)"
        },
        "secondaryGroup": {
          "type": [
            "string",
            "null"
          ],
          "description": "The secondary group from policy category (e.g., Configuration Profiles)"
        },
        "platform": {
          "type": [
            "string",
            "null"
          ],
          "description": "The platform from policy category (e.g., Android Device Administrator)"
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "description": "Policy description from the policyJson if available"
        },
        "isPolicyDeleteDisabled": {
          "type": "boolean",
          "description": "Whether delete protection is enabled for this policy"
        },
        "isPolicyDeployable": {
          "type": "boolean",
          "description": "Whether this policy can be deployed"
        },
        "policyTags": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/policyTag"
          },
          "description": "Policy tags associated with the policy"
        },
        "readOnly": {
          "type": [
            "boolean",
            "null"
          ],
          "description": "Whether the policy is read-only"
        },
        "fullAccessLicenseRequirements": {
          "type": "array",
          "description": "Tenant requires one or more of these licenses for full access to this policy",
          "items": {
            "type": "string"
          }
        }
      },
      "required": [
        "policyName",
        "policyTypeId",
        "inforcerPolicyTypeName",
        "isPolicyDeleteDisabled",
        "isPolicyDeployable",
        "policyTags",
        "fullAccessLicenseRequirements"
      ]
    },
    "policyTag": {
      "type": "object",
      "description": "A tag associated with a tenant",
      "additionalProperties": false,
      "properties": {
        "id": {
          "type": "string",
          "format": "guid",
          "description": "The ID of the tag"
        },
        "name": {
          "type": "string",
          "description": "The name of the tag"
        },
        "description": {
          "type": "string",
          "description": "A description of the tag"
        }
      }
    },
    "similarPolicyResult": {
      "type": "object",
      "description": "Details about a subject policy that closely matches the baseline policy",
      "additionalProperties": false,
      "properties": {
        "policyGuid": {
          "type": [
            "string",
            "null"
          ],
          "format": "guid",
          "description": "GUID of the similar subject policy"
        },
        "policySnapshotId": {
          "type": "string",
          "format": "guid",
          "description": "Snapshot ID of the similar subject policy"
        },
        "policySnapshotVersionId": {
          "type": "string",
          "format": "guid",
          "description": "Snapshot version ID of the similar subject policy"
        },
        "policyName": {
          "type": "string",
          "description": "Display name of the similar subject policy"
        },
        "policyTypeId": {
          "type": "integer",
          "description": "Policy type identifier of the subject policy"
        },
        "policyTypeName": {
          "type": [
            "string",
            "null"
          ],
          "description": "Friendly policy type name of the subject policy"
        },
        "policyCategoryId": {
          "type": [
            "integer",
            "null"
          ],
          "description": "Policy category identifier of the subject policy"
        },
        "policyCategoryName": {
          "type": [
            "string",
            "null"
          ],
          "description": "Human-readable policy category name of the subject policy"
        },
        "policyTags": {
          "type": "array",
          "items": {
            "anyOf": [
              {
                "$ref": "#/$defs/policyTag"
              },
              {
                "type": "object"
              }
            ]
          },
          "description": "Tags associated with the subject policy"
        },
        "isPolicyRenameDisabled": {
          "type": "boolean",
          "description": "Whether the subject policy can be renamed"
        },
        "similarityScore": {
          "type": "number",
          "format": "decimal",
          "description": "Similarity score between baseline and subject policies (0-1)"
        },
        "similarityReason": {
          "$ref": "#/$defs/similarityReasonBreakdown"
        },
        "matchPercentage": {
          "type": "number",
          "format": "decimal",
          "description": "Match percentage between baseline and subject policies (0-100)"
        },
        "diffCount": {
          "type": "integer",
          "description": "Number of differences between the baseline and subject policies"
        },
        "matchCount": {
          "type": "integer",
          "description": "Number of matching properties between the baseline and subject policies"
        },
        "policyDataDiff": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/patchOperation"
          },
          "description": "Differences between the baseline and subject policy definitions"
        },
        "policyAssignmentsDiff": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/patchOperation"
          },
          "description": "Differences between the baseline and subject policy assignments"
        },
        "lastModified": {
          "type": [
            "string",
            "null"
          ],
          "format": "date-time",
          "description": "Timestamp when the subject policy was last modified"
        }
      },
      "required": [
        "policyGuid",
        "policySnapshotId",
        "policyName",
        "policyTypeId",
        "isPolicyRenameDisabled",
        "matchPercentage",
        "diffCount",
        "matchCount",
        "policyDataDiff",
        "policyAssignmentsDiff"
      ]
    },
    "similarityReasonBreakdown": {
      "type": "object",
      "description": "Breakdown of similarity scores by category",
      "additionalProperties": false,
      "properties": {
        "summary": {
          "type": "string",
          "description": "Overall similarity summary"
        },
        "critical": {
          "type": "number",
          "format": "decimal",
          "description": "Critical settings similarity percentage (0-100)"
        },
        "configuration": {
          "type": "number",
          "format": "decimal",
          "description": "Configuration settings similarity percentage (0-100)"
        },
        "assignments": {
          "type": "number",
          "format": "decimal",
          "description": "Assignment similarity percentage (0-100)"
        },
        "metadata": {
          "type": "number",
          "format": "decimal",
          "description": "Metadata similarity percentage (0-100)"
        }
      },
      "required": [
        "summary"
      ]
    },
    "tenantAlignmentDetailedData": {
      "type": "object",
      "description": "Detailed tenant alignment results with individual policy information",
      "additionalProperties": false,
      "properties": {
        "baselineTenantId": {
          "type": "integer",
          "minimum": 1,
          "description": "The baseline tenant ID"
        },
        "subjectTenantId": {
          "type": "integer",
          "minimum": 1,
          "description": "The subject tenant ID"
        },
        "subjectDataTimestamp": {
          "type": "string",
          "format": "date-time",
          "description": "Timestamp of the subject tenant data"
        },
        "baselineDataTimestamp": {
          "type": "string",
          "format": "date-time",
          "description": "Timestamp of the baseline tenant data"
        },
        "alignmentScore": {
          "type": "number",
          "format": "decimal",
          "minimum": 0,
          "maximum": 100,
          "description": "The alignment score percentage"
        },
        "deviatedUnaccepted": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/policyComparisonDetail"
          },
          "description": "Policies that deviate from baseline and are not accepted"
        },
        "matchedPolicies": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/policyComparisonDetail"
          },
          "description": "Policies that match baseline exactly"
        },
        "matchedWithAcceptedDeviations": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/policyComparisonDetail"
          },
          "description": "Policies that match baseline using accepted deviations"
        },
        "additionalInSubjectUnaccepted": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/policyComparisonDetail"
          },
          "description": "Policies present in subject but missing from baseline"
        },
        "missingFromSubjectUnaccepted": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/policyComparisonDetail"
          },
          "description": "Policies present in baseline but missing from subject"
        }
      },
      "required": [
        "baselineTenantId",
        "subjectTenantId",
        "subjectDataTimestamp",
        "baselineDataTimestamp",
        "alignmentScore",
        "deviatedUnaccepted",
        "matchedPolicies",
        "matchedWithAcceptedDeviations",
        "additionalInSubjectUnaccepted",
        "missingFromSubjectUnaccepted"
      ]
    },
    "tenantComparisonData": {
      "type": "object",
      "description": "Tenant comparison results with metrics and policy details",
      "additionalProperties": false,
      "properties": {
        "metrics": {
          "$ref": "#/$defs/alignmentMetricsData"
        },
        "completedAt": {
          "type": "string",
          "format": "date-time",
          "description": "When the comparison was completed"
        },
        "alignment": {
          "$ref": "#/$defs/tenantAlignmentDetailedData",
          "nullable": true,
          "description": "Detailed policy comparison results with full metadata"
        }
      },
      "required": [
        "metrics",
        "completedAt"
      ]
    },
    "variableSubstitutionDetail": {
      "type": "object",
      "description": "Details of a variable substitution found during policy comparison",
      "additionalProperties": false,
      "properties": {
        "variableId": {
          "type": "string",
          "format": "guid",
          "description": "The id of the client variable"
        },
        "variableName": {
          "type": "string",
          "description": "The name of the client variable"
        },
        "baselineValue": {
          "type": [
            "string",
            "null"
          ],
          "description": "The baseline tenant's variable value (null if missing from baseline)"
        },
        "subjectValue": {
          "type": [
            "string",
            "null"
          ],
          "description": "The subject tenant's variable value (null if missing from subject)"
        },
        "description": {
          "type": [
            "string",
            "null"
          ],
          "description": "The optional description of the client variable"
        },
        "propertyPath": {
          "type": "string",
          "description": "The JSON path where this variable substitution occurs in the policy"
        },
        "isHidden": {
          "type": "boolean",
          "description": "Whether or not the variable is marked as hidden, and so the values will be unavailable"
        },
        "isBaselineOnly": {
          "type": "boolean",
          "description": "Whether this variable was found by scanning the baseline policy JSON (true) or by matching a diff between baseline and subject (false). Baseline-only variables are useful for deployment but don't explain a specific diff."
        }
      },
      "required": [
        "variableId",
        "variableName",
        "propertyPath",
        "isBaselineOnly"
      ]
    }
  }
}