<?php

namespace App\Packages\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;
use App\Packages\User\Service\PushNotificationService;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;

/**
 * Class NotificationLike
 * @package App\Packages\User\Notifications
 */
abstract class AbstractNotification implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /** @var User */
    protected $owner;

    /** @var int */
    public $tries = 3;

    public function handle()
    {
        if (!$this->shouldSend()) {
            return;
        }

        if ($this->owner->is_notification_app) {
            $this->sendApplication();
        }

        if ($this->owner->ios_push_token && $this->owner->is_notification_push) {

            $notification = $this->sendPush();
            if ($notification && !$notification->is_sent) {
                /** @var PushNotificationService $pushService */
                $pushService = app()->make(PushNotificationService::class);
                $pushService->sendPushNotification($notification);
            }
        }
    }

    public function shouldSend()
    {
        return false;
    }

    public function sendApplication()
    {
        // Send application notification
    }

    /**
     * @return UserNotificationPush|null
     */
    public function sendPush()
    {
        // Send push notification
    }


}