<?php

namespace CouponsPlus\App\Coupon\Tree\Finders\Sets;

use CouponsPlus\App\Conditions\ItemsSet;
use CouponsPlus\Original\Collections\Collection;
use CouponsPlus\App\Coupon\Tree\Abilities\ItemToDiscount;

class OfferItems
{
    protected ItemsSet $itemsToDiscount;
    /**
     * @var ItemsSet These items are not to be discounted. They were used to make the offer eligible, for example, in a BOGO offer these will be the items that the customer must purchase in full.
     *
     * These were used to make the offer eligible, usually used to exclude them from offer calculations.
     */
    protected ItemsSet $itemsUsedToMakeTheOfferEligibleOnly;
    /**
     * @var Collection<ItemToDiscount> These items are related to an offer, and its use is up to each offer.
     *
     * currently, it is used by get y to suggest the items that are eligible to discount and cannot be added to the cart for many reasons (admin choice or not a specific product or stock issues, etc).
     *
     * So to be more precise, these are not cart items but *products*.
     */
    protected Collection $suggestedItems;

    /**
     * Can be anything. Used by some offers to store extra data.
     */
    protected $extraData = null;

    public function __construct(ItemsSet $itemsToDiscount, ?ItemsSet $itemsUsedToMakeTheOfferEligibleOnly = null, ?Collection $suggestedItems = null)
    {
        $this->itemsToDiscount = $itemsToDiscount;
        $this->itemsUsedToMakeTheOfferEligibleOnly = $itemsUsedToMakeTheOfferEligibleOnly ?? new ItemsSet([]);
        $this->suggestedItems = $suggestedItems ?? new Collection([]);
    }

    public function setItemsToDiscount(ItemsSet $itemsToDiscount): void
    {
        $this->itemsToDiscount = $itemsToDiscount;
    }

    /**
     * Items that should not be discounted by the offer but that they were used to pick the offer.
     */
    public function setItemsUsedToMakeTheOfferEligible(ItemsSet $itemsUsedToMakeTheOfferEligibleOnly): void
    {
        $this->itemsUsedToMakeTheOfferEligibleOnly = $itemsUsedToMakeTheOfferEligibleOnly;
    }

    public function getItemsToDiscount(): ItemsSet
    {
        return $this->itemsToDiscount;
    }

    public function getItemsUsedToMakeTheOfferEligibleOnly(): ItemsSet
    {
        return $this->itemsUsedToMakeTheOfferEligibleOnly;
    }

    public function getAll(): Collection
    {
        return new Collection([
            $this->getItemsToDiscount(),
            $this->getItemsUsedToMakeTheOfferEligibleOnly()
        ]);
    }

    public function getExtraData()
    {
        return $this->extraData;
    }

    public function setExtraData($extraData): void
    {
        $this->extraData = $extraData;
    }
}