import { createClient } from 'https://esm.sh/@supabase/supabase-js@2'

const supabaseUrl = Deno.env.get('SUPABASE_URL') || ''
const supabaseServiceKey = Deno.env.get('SUPABASE_SERVICE_ROLE_KEY') || ''
const supabaseAdmin = createClient(supabaseUrl, supabaseServiceKey)

const { data: store, error: storeError } = await supabaseAdmin
  .from('stores')
  .select(`
    id,
    store_name,
    qdrant_sync_enabled,
    store_sync_config (
      sync_orders,
      sync_customers
    )
  `)
  .eq('id', 'd164a10f-580c-4500-9850-fed3079dd6af')
  .single()

console.log('Store data:', JSON.stringify(store, null, 2))
console.log('store_sync_config:', store?.store_sync_config)
console.log('Type of store_sync_config:', typeof store?.store_sync_config)
console.log('Is array?:', Array.isArray(store?.store_sync_config))

if (store) {
  const syncConfig = (store as any).store_sync_config?.[0] || {}
  console.log('syncConfig:', syncConfig)
  console.log('syncConfig.sync_orders:', syncConfig.sync_orders)
  console.log('syncConfig.sync_orders === true:', syncConfig.sync_orders === true)
}
