<?php

namespace App\Packages\User\Notifications;

use App\Packages\Capsule\Models\Capsule;
use App\Packages\User\Models\User;
use App\Packages\User\Models\UserNotification;
use App\Packages\User\Models\UserNotificationPush;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

/**
 * Class NotificationSubscriber
 * @package App\Packages\User\Notifications
 */
class NotificationSubscriber extends AbstractNotification
{
	/** @var Capsule */
	private $capsule;

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

    /**
	 * @param Capsule $capsule
	 * @param User $userActed
	 *
	 * @internal param Podcast $podcast
	 */
	public function __construct(Capsule $capsule, User $userActed)
	{
		$this->capsule = $capsule;
		$this->owner = $capsule->user;
		$this->userActed = $userActed;
	}

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

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

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

        return $result;
    }
}