USE payer_centric_pay;

INSERT INTO merchants (name, store_code, contact_name, business_number)
VALUES
  ('Northstar Market', 'NSM-001', 'Ari Vega', '94-3839201'),
  ('Harbor Fuel & Go', 'HFG-117', 'Mina Cole', '13-9911840')
ON DUPLICATE KEY UPDATE
  contact_name = VALUES(contact_name),
  business_number = VALUES(business_number);

INSERT INTO shoppers (full_name, mobile_number, auth_pin)
VALUES
  ('Jordan Lee', '+1-415-555-0119', '2580'),
  ('Camila Brooks', '+1-415-555-0147', '4931')
ON DUPLICATE KEY UPDATE
  auth_pin = VALUES(auth_pin);

INSERT INTO payment_methods (shopper_id, label, network, masked_account, token_ref, billing_type, is_default)
SELECT s.id, 'Everyday Debit', 'Visa', '**** 4401', 'tok_demo_visa_4401', 'debit', TRUE
FROM shoppers s
WHERE s.mobile_number = '+1-415-555-0119'
  AND NOT EXISTS (
    SELECT 1 FROM payment_methods pm WHERE pm.token_ref = 'tok_demo_visa_4401'
  );

INSERT INTO payment_methods (shopper_id, label, network, masked_account, token_ref, billing_type, is_default)
SELECT s.id, 'Rewards Credit', 'Mastercard', '**** 8824', 'tok_demo_mc_8824', 'credit', FALSE
FROM shoppers s
WHERE s.mobile_number = '+1-415-555-0119'
  AND NOT EXISTS (
    SELECT 1 FROM payment_methods pm WHERE pm.token_ref = 'tok_demo_mc_8824'
  );

INSERT INTO payment_methods (shopper_id, label, network, masked_account, token_ref, billing_type, is_default)
SELECT s.id, 'Travel Card', 'Amex', '**** 3009', 'tok_demo_amex_3009', 'credit', TRUE
FROM shoppers s
WHERE s.mobile_number = '+1-415-555-0147'
  AND NOT EXISTS (
    SELECT 1 FROM payment_methods pm WHERE pm.token_ref = 'tok_demo_amex_3009'
  );
