<?php

declare(strict_types=1);

namespace App\Domain\PreSave\Jobs;

use App\Domain\PreSave\Services\PreSaveProcessor;
use App\Framework\Worker\Every;
use App\Framework\Worker\Schedule;

/**
 * Process Released Campaigns Job
 *
 * Runs every hour to check for campaigns that should be released
 */
#[Schedule(at: new Every(hours: 1))]
final readonly class ProcessReleasedCampaignsJob
{
    public function __construct(
        private PreSaveProcessor $processor,
    ) {
    }

    /**
     * @return array<string, mixed>
     */
    public function handle(): array
    {
        // Step 1: Mark campaigns as released if release date has passed
        $releaseResults = $this->processor->processReleasedCampaigns();

        // Step 2: Process pending registrations for released campaigns
        $processingResults = $this->processor->processPendingRegistrations();

        return [
            'job' => 'process_released_campaigns',
            'timestamp' => time(),
            'release_phase' => $releaseResults,
            'processing_phase' => $processingResults,
        ];
    }
}
