<?php

namespace App\Model\Services;

use App\Model\Entities\Components\Article\Article;
use App\Model\Entities\Security\User;
use App\Model\Entities\Templates\ArticleTemplate;

class ArticleService extends BaseService
{
    public function findArticle($id)
    {
        return $this->getRepository(Article::class)->find($id);
    }

    public function findAllArticles()
    {
        return $this->getRepository(Article::class)->findAll();
    }


    public function createArticle(User $createdBy, ArticleTemplate $template, $language, $name, $content = null)
    {
        $article = new Article($createdBy);
        $article->setTemplate($template);
        $article->setLanguage($language);

        // todo: fix article content

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

    public function publishArticle(Article $article)
    {
        // todo: add staes to article
//        $article->setState();
    }
}