<?php

namespace App;

use App\Message\RunImageCleanupMessage;
use Symfony\Component\Scheduler\Attribute\AsSchedule;
use Symfony\Component\Scheduler\RecurringMessage;
use Symfony\Component\Scheduler\Schedule as SymfonySchedule;
use Symfony\Component\Scheduler\ScheduleProviderInterface;
use Symfony\Contracts\Cache\CacheInterface;

#[AsSchedule]
class Schedule implements ScheduleProviderInterface
{
    public function __construct(
        private CacheInterface $cache,
    ) {
    }

    public function getSchedule(): SymfonySchedule
    {
        // Rotation is handled at poll time in DeviceImageController — no scheduler needed.
        // DEV/PROD note: when switching to wakeTimes mode, the device only polls
        // at each configured time, so rotation still happens correctly (isDue()
        // fires on each scheduled poll).
        return (new SymfonySchedule())
            ->stateful($this->cache)
            ->processOnlyLastMissedRun(true)
            ->add(
                RecurringMessage::cron('0 * * * *', new RunImageCleanupMessage()),
            );
    }
}
