<?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;

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

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

    public function shouldSend()
    {
        return true;
    }

    public function sendApplication()
    {
        $notification = UserNotification::storeNotification(
            $this->owner,
            TypesNotification::CAPSULE_SUBSCRIBED_HATCHED
        );

        $notification
            ->setUser($this->owner)
            ->setCapsule($this->capsule)
            ->persist();
    }

    public function sendPush()
    {
        $notification = UserNotificationPush::storeNotification(
            $this->owner,
            TypesNotification::CAPSULE_SUBSCRIBED_HATCHED
        );

        $result = $notification
            ->setUser($this->owner)
            ->setCapsule($this->capsule)
            ->persist();

        return $result;
    }
}