# yaml-language-server: $schema=https://api.cerbos.dev/latest/cerbos/policy/v1/Policy.schema.json
---
apiVersion: api.cerbos.dev/v1
derivedRoles:
  name: ai_enablement
  variables:
    import:
    - common_variables
    local:
      principal_ai_can_apollo_mcp_pilot_tenant_list: P.attr.tenants.filter(t, P.attr.tenants[t].roles.exists(r, r == 'ai_can_apollo_mcp_pilot')).map(t,t)
  definitions:
  - name: ai_can_apollo_mcp_pilot
    parentRoles:
    - user
    condition:
      match:
        any:
          of:
          - expr: P.attr.tenants[V.resource_tenant].roles['ai_can_apollo_mcp_pilot'] != null
          - expr: hasIntersection(V.principal_ai_can_apollo_mcp_pilot_tenant_list, V.resource_tenant_hierarchy)
  - name: any_tenant_ai_can_apollo_mcp_pilot
    parentRoles:
    - user
    condition:
      match:
        expr: V.principal_ai_can_apollo_mcp_pilot_tenant_list.size() > 0
