<?php

declare(strict_types=1);

namespace App\Application\Campaign;

use App\Application\Campaign\ValueObjects\Campaign;
use App\Framework\Attributes\Singleton;
use App\Framework\Http\Session\SessionId;

/**
 * Campaign Service
 *
 * Business logic for campaign operations
 */
#[Singleton]
final readonly class CampaignService
{
    public function __construct(
        private CampaignRepository $repository
    ) {
    }

    public function findBySlug(string $slug): ?Campaign
    {
        return $this->repository->findBySlug($slug);
    }

    public function hasUserSaved(string $campaignId, SessionId $sessionId): bool
    {
        return $this->repository->hasUserSaved($campaignId, $sessionId->toString());
    }

    public function recordPreSave(
        string $campaignId,
        string $platform,
        SessionId $sessionId,
        ?string $email = null
    ): void {
        $this->repository->recordPreSave($campaignId, $platform, $sessionId->toString(), $email);
        $this->repository->incrementSaveCount($campaignId);
    }

    public function recordEmailSubscription(
        string $campaignId,
        string $email,
        ?string $name = null,
        bool $newsletter = false
    ): void {
        $this->repository->recordEmailSubscription(
            $campaignId,
            $email,
            $name,
            $newsletter
        );
    }
}
