<?php

declare(strict_types=1);

namespace MauticPlugin\DealFlowBundle\Service;

class CurrencyResolver
{
    public function __construct(
        private readonly array $coreParameters = [],
    ) {
    }

    public function resolve(?string $dealCurrency = null): string
    {
        if ($dealCurrency !== null && $dealCurrency !== '') {
            return $dealCurrency;
        }

        $configCurrency = $this->coreParameters['currency'] ?? null;
        if ($configCurrency !== null && $configCurrency !== '') {
            return $configCurrency;
        }

        return 'USD';
    }

    public function getSymbol(string $currencyCode): string
    {
        return match (strtoupper($currencyCode)) {
            'USD' => '$',
            'EUR' => "\u{20AC}",
            'GBP' => "\u{00A3}",
            'JPY' => "\u{00A5}",
            'CAD' => 'CA$',
            'AUD' => 'A$',
            'CHF' => 'CHF',
            default => $currencyCode.' ',
        };
    }
}
