export default {
    async scheduled(event, env, ctx) {
        console.log('Cron triggered: Pinging /api/cron/reminders');

        const headers = {};
        if (env.CRON_SECRET) {
            headers['Authorization'] = `Bearer ${env.CRON_SECRET}`;
        }

        try {
            const response = await fetch('https://quittraq.com/api/cron/reminders', {
                headers
            });

            console.log(`Ping status: ${response.status} ${response.statusText}`);

            if (!response.ok) {
                const text = await response.text();
                console.error(`Cron trigger failed: ${text}`);
            }
        } catch (err) {
            console.error('Failed to ping cron endpoint:', err);
        }
    },
};
