<?php
defined('ABSPATH') || exit;

class FixLinks_Cron {

    public static function schedule(): void {
        $ev = [
            'fixlinks_crawl_event'     => 'weekly',
            'fixlinks_weekly_email'    => 'weekly',
            'fixlinks_license_recheck' => 'weekly',
            'fixlinks_crawl_batch'     => 'fixlinks_5min',
            'fixlinks_flush_hits'      => 'hourly',
        ];
        foreach ($ev as $hook => $rec) {
            if (!wp_next_scheduled($hook)) wp_schedule_event(time(), $rec, $hook);
        }
    }

    public static function unschedule(): void {
        foreach (['fixlinks_crawl_event', 'fixlinks_weekly_email', 'fixlinks_license_recheck',
                  'fixlinks_crawl_batch', 'fixlinks_flush_hits'] as $hook) {
            $ts = wp_next_scheduled($hook);
            if ($ts) wp_unschedule_event($ts, $hook);
        }
    }

    public static function add_custom_intervals(array $schedules): array {
        $schedules['fixlinks_5min'] = [
            'interval' => 300,
            'display'  => __('Every 5 minutes (FixLinks AI)', 'fixlinks-ai'),
        ];
        return $schedules;
    }
}