-- ============================================================================
-- GMIND INSTITUTE — Phase 2 Settings Migration
-- ============================================================================
-- Inserts default system settings into the `settings` table.
-- Idempotent — safe to run multiple times.
-- ============================================================================

-- Insert all Phase 2 system settings with defaults
-- Uses INSERT IGNORE to avoid overwriting existing values

INSERT IGNORE INTO `settings` (`setting_key`, `setting_value`) VALUES
-- Document Pricing (cost to branch per document)
('cert_cost_certificate', '50'),
('cert_cost_marksheet', '30'),
('cert_cost_id_card', '10'),
('cert_cost_admit_card', '5'),
('cert_cost_affiliation', '0'),
('cert_cost_authorization', '0'),

-- Referral System
('referral_commission_pct', '10'),
('referral_bonus_on_join', '500'),

-- Grade System
('grade_a_plus_min', '90'),
('grade_a_min', '80'),
('grade_b_plus_min', '70'),
('grade_b_min', '60'),
('grade_c_min', '40'),
('default_pass_pct', '40'),

-- Serial Numbers
('cert_serial_prefix', 'GMIND'),
('marksheet_serial_prefix', 'MS'),

-- Verification Portal
('verification_portal_url', '')
ON DUPLICATE KEY UPDATE `setting_value` = VALUES(`setting_value`);

-- Also insert into legacy schema columns
INSERT IGNORE INTO `settings` (`key_name`, `value`) VALUES
('cert_cost_certificate', '50'),
('cert_cost_marksheet', '30'),
('cert_cost_id_card', '10'),
('cert_cost_admit_card', '5'),
('cert_cost_affiliation', '0'),
('cert_cost_authorization', '0'),
('referral_commission_pct', '10'),
('referral_bonus_on_join', '500'),
('grade_a_plus_min', '90'),
('grade_a_min', '80'),
('grade_b_plus_min', '70'),
('grade_b_min', '60'),
('grade_c_min', '40'),
('default_pass_pct', '40'),
('cert_serial_prefix', 'GMIND'),
('marksheet_serial_prefix', 'MS'),
('verification_portal_url', '');

-- Verify:
-- SELECT * FROM settings WHERE setting_key LIKE 'cert_%' OR setting_key LIKE 'referral_%' OR setting_key LIKE 'grade_%';
