<?php

declare(strict_types=1);

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Bridge\Symfony\Bundle\Scheduler;

use CpCreation\VitiCore\Commerce\Catalog\Enrollment\Message\DispatchCatalogEnrollmentsMessage;
use CpCreation\VitiCore\Commerce\Catalog\Outbox\Message\DispatchCatalogChangesMessage;
use CpCreation\VitiCore\Commerce\Catalog\Outbox\Message\PurgeCatalogChangesMessage;
use CpCreation\VitiCore\Commerce\Catalog\Outbox\Message\ReconcileCatalogStockMessage;
use Presta\SitemapBundle\Messenger\DumpSitemapMessage;
use Symfony\Component\Scheduler\Attribute\AsSchedule;
use Symfony\Component\Scheduler\RecurringMessage;
use Symfony\Component\Scheduler\Schedule;
use Symfony\Component\Scheduler\ScheduleProviderInterface;
use Symfony\Contracts\Cache\CacheInterface;

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

    public function getSchedule(): Schedule
    {
        return new Schedule()
            ->add(RecurringMessage::every('1 day', new DumpSitemapMessage()))
            ->add(RecurringMessage::every('1 hour', new MarkAbandonedCartsMessage()))
            ->add(RecurringMessage::every('1 hour', new DispatchAbandonedCartRemindersMessage()))
            ->add(RecurringMessage::every('1 hour', new DispatchReviewInvitationsMessage()))
            ->add(RecurringMessage::every('1 hour', new PublishDueProductReviewsMessage()))
            ->add(RecurringMessage::every('1 hour', new ReconcileCatalogStockMessage()))
            ->add(RecurringMessage::every('1 minute', new DispatchCatalogEnrollmentsMessage()))
            ->add(RecurringMessage::every('1 minute', new DispatchCatalogChangesMessage()))
            ->add(RecurringMessage::every('1 day', new PurgeCatalogChangesMessage()))
            ->add(RecurringMessage::every('1 day', new PurgeReviewDataMessage()))
            ->add(RecurringMessage::every('1 day', new PurgeExpiredRegistrationsMessage()))
            ->add(RecurringMessage::every('5 minutes', new PublishDueBusinessVersionsMessage()))
            ->stateful($this->cache)
        ;
    }
}
