import { db } from '../src/db/client';

async function testSettings() {
  const shop = await db.getDefaultShop();
  console.log('Shop:', shop?.id, shop?.shopify_domain);

  const updated = await db.upsertAppConfiguration({
    id: `config_${shop?.id}`,
    shop_id: shop?.id || 'shop_test',
    shopify_domain: shop?.shopify_domain || 'quickstart-1a79b82e.myshopify.com',
    shopify_access_token_encrypted: 'test_encrypted_token',
    shopify_api_key: 'fcf3c95da56ecc483ade6dabbdb49e92',
    shopify_api_secret_encrypted: null,
    shopify_api_version: '2024-07',
    meta_business_id: '1293265651895106',
    meta_business_name: 'Dha-webile',
    meta_catalog_id: '2100764417471410',
    meta_catalog_name: 'fb data test',
    meta_pixel_id: '2550335385463806',
    meta_pixel_name: 'Master Store Pixel',
    meta_access_token_encrypted: null,
    meta_test_event_code: 'TEST12345',
    created_at: new Date().toISOString(),
    updated_at: new Date().toISOString(),
  });

  console.log('Upserted config:', updated);

  const fetched = await db.getAppConfiguration(shop?.id || '');
  console.log('Fetched config from DB:', fetched);
}

testSettings().catch(console.error);
