<?php

namespace CouponsPlus\App\Coupon\Tree\ItemSetsToDiscount;

use CouponsPlus\App\Coupon\Tree\Notifications\Notification;
use CouponsPlus\App\Coupon\Tree\Notifications\Notifications;
use CouponsPlus\App\Coupon\Tree\Abilities\ItemSetToDiscountHandler;
use CouponsPlus\App\Coupon\Tree\Abilities\OptionalItemSetToDiscountHandler;

class CannotBeAutomaticallyAddedButCanBeAddedManuallyNotificationRegistrarItemSetToDiscountHandler implements ItemSetToDiscountHandler, OptionalItemSetToDiscountHandler
{

    protected Notification $notification;
    protected Notifications $notifications;

    public function __construct(Notification $notification, Notifications $notifications)
    {
        $this->notification = $notification;
        $this->notifications = $notifications;
    }

    public function canHandle(ItemsSetToDiscount $itemsSetToDiscount): bool
    {
        return !$itemsSetToDiscount->productToDiscount->canBeAutomaticallyAddedToTheCart() &&
               $itemsSetToDiscount->productToDiscount->canBeManuallyAddedToTheCart();
    }

    public function handle(ItemsSetToDiscount $itemSetToDiscount)
    {
        $this->notifications->addUnique($this->notification);
    }
}