<?php

namespace common\logic\Order\ProductOrder\Service;

use common\helpers\Price;
use common\logic\AbstractService;
use common\logic\Order\Order\Model\Order;
use common\logic\Order\ProductOrder\Model\ProductOrder;
use common\logic\SolverInterface;

class ProductOrderSolver extends AbstractService implements SolverInterface
{
    /**
     * Retourne le prix du produit avec taxe
     */
    public function getPriceWithTax(ProductOrder $productOrder): float
    {
        return Price::getPriceWithTax($productOrder->price, $productOrder->taxRate->value);
    }

    public function getPriceByTypeTotal(ProductOrder $productOrder, string $typeTotal = Order::AMOUNT_TOTAL): float
    {
        if ($typeTotal == Order::INVOICE_AMOUNT_TOTAL && $productOrder->invoice_price) {
            return $productOrder->invoice_price;
        }

        return $productOrder->price;
    }
}