<?php


namespace App\Model\Services;


use App\Model\Entities\Components\Post;
use App\Model\Entities\Security\User;
use App\Model\Interfaces\IMessenger;
use Kdyby\Doctrine\EntityRepository;

class MessengerService extends BaseService
{
    /** @var  EntityRepository */
    protected $posts;

    protected function startup()
    {
        $this->posts = $this->getRepository(Post::class);
    }


    public function createPost(User $createdBy, IMessenger $messenger, string $title, string $message, Post $reply = null) : Post
    {
        $post = new Post($createdBy);
        $post->setMessenger($messenger);
        $post->setTitle($title);
        $post->setMessage($message);
        $post->setReply($reply);

        $this->persist($post);
        return $post;
    }

    public function findPostById(int $id)
    {
        return $this->posts->find($id);
    }
}