<?php

namespace App\Packages\v4\User\Notifications;

use App\Packages\Capsule\Models\Capsule;
use App\Packages\Capsule\Models\CapsuleComment;
use App\Packages\User\Models\User;
use App\Packages\User\Models\UserNotification;
use App\Packages\User\Models\UserNotificationPush;

/**
 * Class NotificationMentionComment
 * @package App\Packages\User\Notifications
 */
class NotificationMentionComment extends AbstractNotification
{
    /** @var CapsuleComment */
    private $capsuleComment;

    /** @var User */
    private $userActed;

    /** @var Capsule */
    private $capsule;

    /**
     * @param CapsuleComment $capsuleComment
     * @param User $userActed
     */
    public function __construct(CapsuleComment $capsuleComment, User $userActed)
    {
        $this->owner = $userActed;
        $this->capsuleComment = $capsuleComment;
        $this->capsule = $capsuleComment->capsule;
        $this->userActed = $capsuleComment->user;
    }

    /**
     * @return bool
     */
    public function shouldSend()
    {
        return ($this->owner->id === $this->userActed->id) ? false : true;
    }

    public function sendApplication()
    {
        $notification = UserNotification::storeNotification($this->owner, TypesNotification::COMMENT_MENTION);
        $notification
            ->setCapsule($this->capsule)
            ->setComment($this->capsuleComment)
            ->setUser($this->userActed)
            ->persist();
    }

    public function sendPush()
    {
        $notification = UserNotificationPush::storeNotification($this->owner, TypesNotification::COMMENT_MENTION);
        $result = $notification
            ->setCapsule($this->capsule)
            ->setComment($this->capsuleComment)
            ->setUser($this->userActed)
            ->persist();

        return $result;
    }
}