{
    "$schema": "https://json-schema.org/draft/2020-12/schema",
    "id": "cerbos:///principal.json",
    "required": ["type", "tenants"],
    "type": "object",
    "properties": {
        "type": {
            "type": "string",
            "enum": ["machine", "human"]
        },
        "tenants": {
            "type": "object",
            "additionalProperties": {
                "$ref": "#/$defs/tenant"
            }
        },
        "impersonated_by_identity_uuid": {
            "type": "string",
            "minLength": 1
        }
    },
    "$defs": {
        "tenant": {
            "type": "object",
            "required": [ "tenant_uuid", "tenant_type", "roles"],
            "properties": {
                "tenant_uuid": {
                    "type": "string",
                    "description": "The account, subaccount, etc. uuid"
                },
                "tenant_type": {
                    "type": "string",
                    "enum": ["company_brand", "account", "subaccount", "label_participant", "parent_company"]
                },
                "tenant_hierarchy": {"type": "string"},
                "roles": {
                    "type": "object",
                    "additionalProperties": {
                        "$ref": "#/$defs/role"
                    }
                }
            }
        },
        "role": {
            "type": "object",
            "required": ["role"],
            "properties": {
                "role": {
                    "type": "string"
                }
            }
        }
    }
}
