<?php
namespace App\Domain\Feeds\Action;

use App\Domain\Feeds\ToFeedAction;
use App\Domain\Tags\Action\CreateTagAction;

class CreateFeedAction
{
    public $tooFeedAction;
    public $tagAction;


    public function __construct(ToFeedAction $tooFeedAction, CreateTagAction $tagAction)
    {
        $this->tooFeedAction = $tooFeedAction;
        $this->tagAction = $tagAction;
    }

    public function __invoke($dataFeed)
    {

        $feed = ($this->tooFeedAction)($dataFeed);

        if(count($dataFeed->tags)){
            $idsTag = ($this->tagAction)($dataFeed->tags);
            $feed->tags()->sync($idsTag);
        }
    }
}
