<?php

namespace Planaday\Entities;

use Planaday\Config\General\Price\PriceSettings;
use Planaday\Platform\PlatformAbstraction\LocalizationController;
use Planaday\Utility\DependencyInjection\Attributes\Scoped;

#[Scoped]
class CostDataUtility {
	public function __construct(
		protected LocalizationController $translationService,
		protected PriceSettings $priceSettings
	) {}

	/**
	 * @param CostsData $costsData
	 * @param bool $hasTwoLabels
	 * @param bool $includesPerPersonText
	 * @param bool|null $taxOverride
	 *
	 * @return string
	 */
	public function getPriceString(CostsData $costsData, bool $hasTwoLabels, bool $includesPerPersonText = false, ?bool $taxOverride = null):string {
		$excludingTaxFirst = !($taxOverride ?? $this->priceSettings->isIncludingTax());
		$showTaxLabels = $this->priceSettings->isWithTaxLabel();

		$includingTaxLabel = $showTaxLabels ? ' ' . $this->translationService->translate('incl. BTW') : '';
		$excludingTaxLabel = $showTaxLabels ? ' ' . $this->translationService->translate('ex. BTW') : '';

		if ($includesPerPersonText){
			$includingTaxLabel = ' ' . $this->translationService->translate('p/p') . $includingTaxLabel;
			$excludingTaxLabel = ' ' . $this->translationService->translate('p/p') . $excludingTaxLabel;
		}

		$includingTaxPrice = number_format($costsData->getPriceWithTax(), 2, $this->priceSettings->isUsePointsForDecimals() ? '.' : ',', '') . $includingTaxLabel;
		$excludingTaxPrice = number_format($costsData->getCost(), 2, $this->priceSettings->isUsePointsForDecimals() ? '.' : ',', '') . $excludingTaxLabel;

		$output = '€';
		$output .= ($excludingTaxFirst ? $excludingTaxPrice : $includingTaxPrice);
		if ($hasTwoLabels) $output .= ' / €' . ($excludingTaxFirst ? $includingTaxPrice : $excludingTaxPrice);

		return $output;
	}
}