<?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 CartPromo
{
    public const STATUS_APPLIED = 'applied';
    public const STATUS_PENDING_ADDRESS = 'pending_address';
    public const STATUS_PENDING_AUTO = 'pending_auto';
    public const STATUS_INVALID = 'invalid';

    public function __construct(
        public ?string $code = null,
        public ?string $title = null,
        public ?string $promoId = null,
        public bool $auto = false,
        public ?int $amountTTC = null,
        public ?float $percent = null,
        public bool $onShipping = false,
        public bool $withShippingFees = false,
        public int $discountItemsTTC = 0,
        public int $discountShippingTTC = 0,
        public ?string $giftVariantId = null,
        public ?string $giftProductName = null,
        public ?string $giftTypeName = null,
        public ?string $giftUnitLabel = null,
        public ?string $giftImagePath = null,
        public ?int $giftOriginalUnitPriceTTC = null,
        public int $giftQuantity = 0,
    ) {
    }

    public function getDiscountTotalTTC(): int
    {
        return max(0, $this->discountItemsTTC + $this->discountShippingTTC);
    }

    public function getGiftTotalTTC(): int
    {
        return max(0, ($this->giftOriginalUnitPriceTTC ?? 0) * $this->giftQuantity);
    }

    public function getBenefitTotalTTC(): int
    {
        return max(0, $this->getDiscountTotalTTC() + $this->getGiftTotalTTC());
    }
}
