
bucket_definitions:
  global:
    data:
      - SELECT * FROM survey
      - SELECT * FROM survey_multiple_choice
      - SELECT * FROM survey_questions
      - SELECT * FROM category_images

  user_data:
    parameters:
      - SELECT request.user_id() as id
    data:
      - SELECT * FROM customer_user
        WHERE id = bucket.id
      - SELECT * FROM app_user
        WHERE id = bucket.id

  user_stores:     
    parameters:  
    # Just use the user_id as the only parameter       
    - SELECT request.user_id() as user_id 
      FROM store_user_link
      WHERE user_id = request.user_id()
    data:       
    # Sync all stores belonging to the user 
    - SELECT id, name, created_at, gps, region, channel, store_code, active_products, channel_image, oos, negative_stock, soh_no_sales, no_sales_100_days, total_soh, availability, fixed_count, not_fixed_count, baking_aids, beans, beverages, condiments_s, desserts, fruit, gravy, infant_foods, jam, meals, meat, salads_pickels, spices_season, tomato, tomato_paste, vegetables, week_start_date, user_id, store_id, promos, kaching, category_data, customer_id FROM store_user_link 
      WHERE user_id = bucket.user_id
   

        
  user_store_data:
    parameters:
      - SELECT store_code FROM store_user_link
        WHERE user_id = request.user_id()
    data:
      - SELECT * FROM kaching_gallery
        WHERE store_code = bucket.store_code
      - SELECT * FROM survey_store_link
        WHERE store_code = bucket.store_code
        AND status = 'Incomplete'
        AND archived = 0
        AND submitted = FALSE
      - SELECT * FROM survey_responses
        WHERE store_code = bucket.store_code
      - SELECT * FROM kaching_linked_users
        WHERE store_code = bucket.store_code
        AND archived = 0
      - SELECT * FROM store_promo
        WHERE store_code = bucket.store_code
        AND archived = 0
      - SELECT * FROM promo_gallery
        WHERE store_code = bucket.store_code
      - SELECT * FROM promos_linked_users
        WHERE store_code = bucket.store_code
        AND archived = 0
      - SELECT * FROM product_images
        WHERE store_code = bucket.store_code
      - SELECT * FROM product_store
        WHERE store_code = bucket.store_code
      - SELECT id, name, status, customer_id, updated_at, note, barcode, chain, store_name, category, brand, product, variant, size, image_url, week_start_date, store_soh, system_dros, last_sold, created_at, store_code, product_id, article, dc_soh, last_ordered, last_received, archived, task_name , category_image FROM task
        WHERE store_code = bucket.store_code
        AND archived = 0
      