<?php

/*
 * This file is part of the VITICORE2 package.
 *
 * (c) CP Creation <web@cpcreation.fr>
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 */

namespace CpCreation\VitiCore\Cart;

final class CartPromos
{
    /**
     * @param list<CartPromo> $items
     */
    public function __construct(
        public array $items = [],
    ) {
    }

    public function first(): ?CartPromo
    {
        return $this->items[0] ?? null;
    }

    public function clear(): void
    {
        $this->items = [];
    }

    public function setFirst(CartPromo $promo): void
    {
        $this->items[0] = $promo;
        $this->items = array_values($this->items);
    }

    public function add(CartPromo $promo): void
    {
        $this->items[] = $promo;
    }
}
