-- Run this once in phpMyAdmin.
-- Creates a control table so cron jobs can be listed, described, and
-- enabled/disabled from Website Manage (auth/sitesetting.php), and seeds
-- it with the existing crons plus the new subscription auto-expiry cron.

CREATE TABLE IF NOT EXISTS `cron_jobs` (
  `id` INT(11) NOT NULL AUTO_INCREMENT,
  `job_key` VARCHAR(64) NOT NULL UNIQUE,
  `name` VARCHAR(191) NOT NULL,
  `description` VARCHAR(255) DEFAULT NULL,
  `script_path` VARCHAR(255) NOT NULL,
  `recommended_frequency` VARCHAR(100) DEFAULT NULL,
  `is_enabled` TINYINT(1) NOT NULL DEFAULT 1,
  `last_run_at` DATETIME DEFAULT NULL,
  `last_run_summary` VARCHAR(255) DEFAULT NULL,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

INSERT INTO `cron_jobs` (`job_key`, `name`, `description`, `script_path`, `recommended_frequency`, `is_enabled`) VALUES
('subscription_expiry', 'Subscription Auto-Expiry', 'Expires user_subscriptions whose end_date has passed. Works for Day/Week/Month/Year plans alike, since expiry is date-based.', 'crons/subscription_expiry.php', 'Every 5-10 minutes', 1),
('hdfc_session', 'HDFC Session Refresh', 'Refreshes HDFC merchant login sessions.', 'crons/cron.php', 'Twice an hour', 1),
('cron2', 'Cron Job 2', 'Legacy scheduled task.', 'crons/cron2.php', 'Twice a day', 1),
('cron3', 'Cron Job 3', 'Legacy scheduled task.', 'crons/cron3.php', 'Every 1 minute', 1),
('cron4', 'Cron Job 4', 'Legacy scheduled task.', 'crons/cron4.php', 'Every 1 minute', 1),
('cron5', 'Cron Job 5', 'Legacy scheduled task.', 'crons/cron5.php', 'Not specified - confirm with developer', 1),
('cron6', 'Cron Job 6', 'Legacy scheduled task.', 'crons/cron6.php', 'Not specified - confirm with developer', 1),
('cron_all', 'Run All (combined)', 'Triggers cron.php through cron6.php in one call.', 'crons/cron_all.php', 'Not specified - confirm with developer', 1),
('payindia', 'PayIndia Job', 'Legacy scheduled task.', 'crons/payindia.php', 'Not specified - confirm with developer', 1)
ON DUPLICATE KEY UPDATE job_key = job_key;
