# Define sync rules to control which data is synced to each user
# See the docs: https://docs.powersync.com/usage/sync-rules
bucket_definitions:
  global:
    data:
      # Sync all tasks for admin view or similar
      - SELECT * FROM task
      - SELECT * FROM store
      - SELECT * FROM app_user
      - SELECT * FROM store_user_link

  user_tasks:
    parameters:
      # Get store codes for current user
      - SELECT 
          store_code
        FROM store_user_link
        WHERE user_id = request.user_id()
    data:
      # Sync only tasks with matching store codes
      - SELECT * FROM task
        WHERE store_code = bucket.store_code
        
  user_stores:
    parameters:
      # Get store codes for current user
      - SELECT 
          store_code
        FROM store_user_link
        WHERE user_id = request.user_id()
    data:
      # Sync only stores with matching store codes
      - SELECT * FROM store
        WHERE store_code = bucket.store_code
