-- Patch v34: Login pelanggan terpisah tanpa password memakai ID pelanggan atau nomor WhatsApp.
INSERT IGNORE INTO roles (id, code, name, description) VALUES
(6, 'pelanggan', 'Pelanggan', 'Portal pelanggan untuk melihat status layanan, tagihan, pembayaran, dan ticket keluhan');

ALTER TABLE customers ADD COLUMN IF NOT EXISTS customer_code VARCHAR(40) NULL AFTER id;
ALTER TABLE customers ADD INDEX IF NOT EXISTS idx_customers_code (customer_code);
UPDATE customers
SET customer_code = CONCAT('CUST', LPAD(id, 6, '0'))
WHERE customer_code IS NULL OR customer_code = '';

INSERT INTO settings (setting_key, setting_value) VALUES
('customer_portal_login_mode', 'passwordless'),
('customer_portal_login_page', 'pelanggan-login.php'),
('customer_portal_login_template', 'Halo {{customer_name}}, akses portal pelanggan Anda sudah aktif.

URL Login Pelanggan: {{login_url}}
ID Pelanggan: {{customer_code}}
Nomor WA: {{phone_login}}

Login tanpa password.')
ON DUPLICATE KEY UPDATE setting_value = VALUES(setting_value);
