<?php

namespace App\Controller\Blog;

use App\Core\Controller\Site\PageController;
use App\Core\Site\SiteRequest;
use App\Core\Site\SiteStore;
use App\Entity\Blog\PostFollow;
use App\Manager\PostFollowManager;

class PostFollowController extends PageController
{
    protected PostFollowManager $manager;

    public function __construct(PostFollowManager $manager, SiteRequest $siteRequest, SiteStore $siteStore)
    {
        parent::__construct($siteRequest, $siteStore);

        $this->manager = $manager;
    }

    public function enable(PostFollow $postFollow)
    {
        $this->manager->enable($postFollow);

        $this->addFlash('success', 'Votre e-mail a bien été confirmé.');

        return $this->redirectToRoute('blog_menu_post', [
            'post' => $postFollow->getPost()->getId(),
            'slug' => $postFollow->getPost()->getSlug(),
            '_domain' => $this->siteRequest->getDomain(),
        ]);
    }

    public function disable(PostFollow $postFollow)
    {
        $this->manager->disable($postFollow);

        $this->addFlash('success', 'Vous ne recevrez plus de notification pour cet article.');

        return $this->redirectToRoute('blog_menu_post', [
            'post' => $postFollow->getPost()->getId(),
            'slug' => $postFollow->getPost()->getSlug(),
            '_domain' => $this->siteRequest->getDomain(),
        ]);
    }
}
