SET NAMES utf8mb4 COLLATE utf8mb4_unicode_ci;

-- MiFaPay 是 H5 统一三方支付入口；迁移只写国家/支付方式清单，真实商户号、商户标识、商户私钥、平台公钥必须放运行环境配置。
-- 所有截图内方式默认打开；已有正数汇率继续保留，避免迁移覆盖运营已经维护过的 USD->本币汇率。
SET @now_ms = CAST(UNIX_TIMESTAMP(UTC_TIMESTAMP(3)) * 1000 AS UNSIGNED);

INSERT INTO third_party_payment_channels (
  app_code, provider_code, provider_name, status, sort_order, created_at_ms, updated_at_ms
) VALUES ('lalu', 'mifapay', 'MiFaPay', 'active', 10, @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE
  provider_name = VALUES(provider_name),
  status = VALUES(status),
  sort_order = VALUES(sort_order),
  updated_at_ms = VALUES(updated_at_ms);

-- 存量库可能已经写入过早期测试方式；先关闭不在 MiFaPay 当前支持清单内的方式，H5 才不会展示未开通入口。
UPDATE third_party_payment_methods
SET status = 'disabled', updated_at_ms = @now_ms
WHERE app_code = 'lalu'
  AND provider_code = 'mifapay'
  AND NOT (
    (country_code = 'ID' AND pay_way = 'BankTransfer' AND pay_type = 'BCA') OR
    (country_code = 'ID' AND pay_way = 'BankTransfer' AND pay_type = 'BNI') OR
    (country_code = 'ID' AND pay_way = 'BankTransfer' AND pay_type = 'BRI') OR
    (country_code = 'ID' AND pay_way = 'BankTransfer' AND pay_type = 'Mandiri') OR
    (country_code = 'ID' AND pay_way = 'BankTransfer' AND pay_type = 'Permata') OR
    (country_code = 'ID' AND pay_way = 'Ewallet' AND pay_type = 'DANA') OR
    (country_code = 'ID' AND pay_way = 'Ewallet' AND pay_type = 'LinkAja') OR
    (country_code = 'ID' AND pay_way = 'Ewallet' AND pay_type = 'OVO') OR
    (country_code = 'ID' AND pay_way = 'Ewallet' AND pay_type = 'ShopeePay') OR
    (country_code = 'ID' AND pay_way = 'QR' AND pay_type = 'QRIS') OR
    (country_code = 'VN' AND pay_way = 'BankTransfer' AND pay_type = 'VN_BankTransfer') OR
    (country_code = 'VN' AND pay_way = 'QR' AND pay_type = 'VietQR') OR
    (country_code = 'BH' AND pay_way = 'Card' AND pay_type = 'CreditCard') OR
    (country_code = 'QA' AND pay_way = 'Card' AND pay_type = 'CreditCard') OR
    (country_code = 'OM' AND pay_way = 'Card' AND pay_type = 'CreditCard') OR
    (country_code = 'AE' AND pay_way = 'Card' AND pay_type = 'CreditCard') OR
    (country_code = 'KW' AND pay_way = 'Card' AND pay_type = 'Knet') OR
    (country_code = 'SA' AND pay_way = 'Card' AND pay_type = 'MADA') OR
    (country_code = 'SA' AND pay_way = 'Ewallet' AND pay_type = 'ApplePay') OR
    (country_code = 'SA' AND pay_way = 'Ewallet' AND pay_type = 'STCPay') OR
    (country_code = 'IN' AND pay_way = 'Ewallet' AND pay_type = 'BHIM') OR
    (country_code = 'IN' AND pay_way = 'Ewallet' AND pay_type = 'GooglePay') OR
    (country_code = 'IN' AND pay_way = 'Ewallet' AND pay_type = 'Mobikwik') OR
    (country_code = 'IN' AND pay_way = 'Ewallet' AND pay_type = 'Paytm') OR
    (country_code = 'IN' AND pay_way = 'Ewallet' AND pay_type = 'PhonePe') OR
    (country_code = 'IN' AND pay_way = 'Ewallet' AND pay_type = 'UPI') OR
    (country_code = 'BD' AND pay_way = 'Ewallet' AND pay_type = 'bKash') OR
    (country_code = 'PK' AND pay_way = 'Ewallet' AND pay_type = 'Easypaisa') OR
    (country_code = 'PK' AND pay_way = 'Ewallet' AND pay_type = 'JazzCash') OR
    (country_code = 'EG' AND pay_way = 'Ewallet' AND pay_type = 'FawryPay') OR
    (country_code = 'EG' AND pay_way = 'Ewallet' AND pay_type = 'Meeza') OR
    (country_code = 'EG' AND pay_way = 'Ewallet' AND pay_type = 'Orange') OR
    (country_code = 'EG' AND pay_way = 'Ewallet' AND pay_type = 'Vodafone') OR
    (country_code = 'PH' AND pay_way = 'Ewallet' AND pay_type = 'Gcash') OR
    (country_code = 'PH' AND pay_way = 'Ewallet' AND pay_type = 'PayMaya') OR
    (country_code = 'PH' AND pay_way = 'QR' AND pay_type = 'QRPH')
  );

INSERT INTO third_party_payment_methods (
  app_code, provider_code, country_code, country_name, currency_code, pay_way, pay_type,
  method_name, logo_url, status, usd_to_currency_rate, sort_order, created_at_ms, updated_at_ms
) VALUES
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'BankTransfer', 'BCA', 'BCA Bank', '', 'active', 1, 110, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'BankTransfer', 'BNI', 'BNI Bank', '', 'active', 1, 120, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'BankTransfer', 'BRI', 'BRI Bank', '', 'active', 1, 130, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'BankTransfer', 'Mandiri', 'Mandiri Bank', '', 'active', 1, 140, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'BankTransfer', 'Permata', 'Permata Bank', '', 'active', 1, 150, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'Ewallet', 'DANA', 'DANA', '', 'active', 1, 160, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'Ewallet', 'LinkAja', 'LinkAja', '', 'active', 1, 170, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'Ewallet', 'OVO', 'OVO', '', 'active', 1, 180, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'Ewallet', 'ShopeePay', 'ShopeePay', '', 'active', 1, 190, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'ID', 'Indonesia', 'IDR', 'QR', 'QRIS', 'QRIS', '', 'active', 1, 200, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'VN', 'Vietnam', 'VND', 'BankTransfer', 'VN_BankTransfer', 'Vietnam Bank Transfer', '', 'active', 1, 210, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'VN', 'Vietnam', 'VND', 'QR', 'VietQR', 'VietQR', '', 'active', 1, 220, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'BH', 'Bahrain', 'BHD', 'Card', 'CreditCard', 'Bahrain Credit Card', '', 'active', 1, 310, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'QA', 'Qatar', 'QAR', 'Card', 'CreditCard', 'Qatar Credit Card', '', 'active', 1, 410, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'OM', 'Oman', 'OMR', 'Card', 'CreditCard', 'Oman Credit Card', '', 'active', 1, 510, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'AE', 'United Arab Emirates', 'AED', 'Card', 'CreditCard', 'UAE Credit Card', '', 'active', 1, 610, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'KW', 'Kuwait', 'KWD', 'Card', 'Knet', 'KNET', '', 'active', 1, 710, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'SA', 'Saudi Arabia', 'SAR', 'Card', 'MADA', 'MADA', '', 'active', 1, 810, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'SA', 'Saudi Arabia', 'SAR', 'Ewallet', 'ApplePay', 'ApplePay', '', 'active', 1, 820, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'SA', 'Saudi Arabia', 'SAR', 'Ewallet', 'STCPay', 'STCPay', '', 'active', 1, 830, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'IN', 'India', 'INR', 'Ewallet', 'BHIM', 'BHIM', '', 'active', 1, 910, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'IN', 'India', 'INR', 'Ewallet', 'GooglePay', 'GooglePay', '', 'active', 1, 920, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'IN', 'India', 'INR', 'Ewallet', 'Mobikwik', 'Mobikwik', '', 'active', 1, 930, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'IN', 'India', 'INR', 'Ewallet', 'Paytm', 'Paytm', '', 'active', 1, 940, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'IN', 'India', 'INR', 'Ewallet', 'PhonePe', 'PhonePe', '', 'active', 1, 950, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'IN', 'India', 'INR', 'Ewallet', 'UPI', 'UPI', '', 'active', 1, 960, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'BD', 'Bangladesh', 'BDT', 'Ewallet', 'bKash', 'bKash', '', 'active', 1, 1010, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'PK', 'Pakistan', 'PKR', 'Ewallet', 'Easypaisa', 'Easypaisa', '', 'active', 1, 1110, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'PK', 'Pakistan', 'PKR', 'Ewallet', 'JazzCash', 'JazzCash', '', 'active', 1, 1120, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'EG', 'Egypt', 'EGP', 'Ewallet', 'FawryPay', 'FawryPay', '', 'active', 1, 1210, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'EG', 'Egypt', 'EGP', 'Ewallet', 'Meeza', 'Meeza', '', 'active', 1, 1220, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'EG', 'Egypt', 'EGP', 'Ewallet', 'Orange', 'Orange', '', 'active', 1, 1230, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'EG', 'Egypt', 'EGP', 'Ewallet', 'Vodafone', 'Vodafone', '', 'active', 1, 1240, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'PH', 'Philippines', 'PHP', 'Ewallet', 'Gcash', 'GCash', '', 'active', 1, 1310, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'PH', 'Philippines', 'PHP', 'Ewallet', 'PayMaya', 'PayMaya', '', 'active', 1, 1320, @now_ms, @now_ms),
  ('lalu', 'mifapay', 'PH', 'Philippines', 'PHP', 'QR', 'QRPH', 'QRPH', '', 'active', 1, 1330, @now_ms, @now_ms)
ON DUPLICATE KEY UPDATE
  country_name = VALUES(country_name),
  currency_code = VALUES(currency_code),
  method_name = VALUES(method_name),
  status = VALUES(status),
  usd_to_currency_rate = IF(usd_to_currency_rate > 0, usd_to_currency_rate, VALUES(usd_to_currency_rate)),
  sort_order = VALUES(sort_order),
  updated_at_ms = VALUES(updated_at_ms);
