<?php

namespace App\EntityListener;

use App\Entity\Campaign;
use App\Entity\Campaign\LandingPage;
use App\Service\Campaign\LandingPageService;
use Symfony\Component\DependencyInjection\ContainerInterface;

final class LandingPageCampaignListener
{
    /**
     * @var ContainerInterface
     */
    private $container;

    public function __construct(ContainerInterface $container)
    {
        $this->container = $container;
    }

    public function postPersist(Campaign $campaign)
    {
        $landingPageService = $this->container->get(LandingPageService::class);

        $landingPage = (new LandingPage())
            ->setCampaign($campaign)
            ->setUrl($campaign->getDomain()->getFullUrl())
            ->setDescription('Homepage');

        $landingPageService->save($landingPage);
    }
}
