-- Admin-configurable mobile push notification schedule.
-- Import after 15-push-notifications.sql.

CREATE TABLE IF NOT EXISTS `push_notification_settings` (
    `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
    `reminder_days` JSON NOT NULL,
    `send_time` TIME NOT NULL DEFAULT '09:00:00',
    `timezone` VARCHAR(255) NOT NULL DEFAULT 'Asia/Kuala_Lumpur',
    `is_enabled` TINYINT(1) NOT NULL DEFAULT 1,
    `updated_by` BIGINT UNSIGNED NULL,
    `created_at` TIMESTAMP NULL DEFAULT NULL,
    `updated_at` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

INSERT INTO `push_notification_settings`
    (`reminder_days`, `send_time`, `timezone`, `is_enabled`, `created_at`, `updated_at`)
SELECT JSON_ARRAY(90, 60, 30, 15, 7, 1, 0), '09:00:00', 'Asia/Kuala_Lumpur', 1, NOW(), NOW()
WHERE NOT EXISTS (SELECT 1 FROM `push_notification_settings`);

SELECT * FROM `push_notification_settings`;
