# Test view for validating two-dimensional policy behavior
# Matches the diagram in CompilerApi.ts:559-647
#
# Base cube has no policies - the view applies the access policies
#
# Policy 1: covers members a, b with row filter R1 (id < 500)
# Policy 2: covers members b, c with row filter R2 (id >= 500)
#
# Expected behavior:
#   Query (a, b)    → Only Policy 1 applies → R1 rows (id < 500)
#   Query (b, c)    → Only Policy 2 applies → R2 rows (id >= 500)
#   Query (b)       → Both policies apply   → R1 ∪ R2 rows (all rows)
#   Query (a, b, c) → Neither covers all    → Empty result (denied)

cubes:
  # Base cube with no access policy
  - name: policy_overlap_base
    sql_table: public.line_items

    dimensions:
      - name: id
        sql: id
        type: number
        primary_key: true

      # Member "a" - only covered by Policy 1
      - name: member_a
        sql: order_id
        type: number

      # Member "b" - covered by both Policy 1 and Policy 2
      - name: member_b
        sql: product_id
        type: number

      # Member "c" - only covered by Policy 2
      - name: member_c
        sql: quantity
        type: number

    measures:
      - name: count
        type: count

views:
  # View with two-dimensional access policies
  - name: policy_overlap_test
    cubes:
      - join_path: policy_overlap_base
        includes: "*"

    access_policy:
      # Policy 1: covers members a, b (and count, id for filtering) with row filter R1 (id < 500)
      - group: "*"
        member_level:
          includes:
            - id
            - count
            - member_a
            - member_b
        row_level:
          filters:
            - member: id
              operator: lt
              values:
                - "500"

      # Policy 2: covers members b, c (and count, id for filtering) with row filter R2 (id >= 500)
      - group: "policy2_group"
        member_level:
          includes:
            - id
            - count
            - member_b
            - member_c
        row_level:
          filters:
            - member: id
              operator: gte
              values:
                - "500"
