-- SQL to reset upload flags so all products are reuploaded
-- Run these statements to reset Shopify and Google Merchant Centre upload status

-- ============================================
-- RESET SHOPIFY UPLOAD FLAGS
-- ============================================
-- Reset the added_shopify flag in amazon_products table
-- This will make all products eligible for Shopify upload again
UPDATE amazon_products 
SET added_shopify = 0,
    added_shopify_at = NULL
WHERE added_shopify = 1;

-- Optional: Clear Shopify IDs if you want to force recreation
-- UPDATE amazon_products 
-- SET shopify_product_id = NULL,
--     shopify_variant_id = NULL,
--     shopify_inventory_item_id = NULL,
--     added_shopify = 0,
--     added_shopify_at = NULL;

-- ============================================
-- RESET GOOGLE MERCHANT CENTRE UPLOAD FLAGS
-- ============================================
-- Reset the added_google_merch flag in shopify_product_imports table
-- This will make all products eligible for Google Merchant Centre upload again
UPDATE shopify_product_imports 
SET added_google_merch = 0
WHERE added_google_merch = 1;

-- ============================================
-- OPTIONAL: CLEAR TRACKING TABLES
-- ============================================
-- Clear Google Merchant upload tracking (optional - only if you want to remove history)
-- DELETE FROM google_merchant_uploads;

-- Reset shopify_product_imports status to pending (optional - only if you want to reprocess)
-- UPDATE shopify_product_imports 
-- SET status = 'pending',
--     shopify_product_id = NULL,
--     error_message = NULL
-- WHERE status = 'success';

-- ============================================
-- VERIFICATION QUERIES
-- ============================================
-- Check how many products will be reuploaded to Shopify:
-- SELECT COUNT(*) as products_to_upload 
-- FROM amazon_products 
-- WHERE active = 1 
--   AND fulfillment = 'FBM' 
--   AND fulfillable_quantity > 0 
--   AND (added_shopify IS NULL OR added_shopify = 0)
--   AND isbn IS NOT NULL AND isbn <> ''
--   AND pcondition IS NOT NULL AND pcondition <> '';

-- Check how many products will be reuploaded to Google Merchant Centre:
-- SELECT COUNT(*) as products_to_upload 
-- FROM shopify_product_imports 
-- WHERE status = 'success' 
--   AND shopify_product_id IS NOT NULL 
--   AND url IS NOT NULL 
--   AND (added_google_merch IS NULL OR added_google_merch = 0);

