<?php

namespace Opencart\Extension\Alsendo\DTO;

class MoneyDTO
{
    public int $amount;
    public string $currency;

    private const CURRENCY_SYMBOLS = [
        'PLN' => ['symbol' => 'zł', 'position' => 'right'],
        'RON' => ['symbol' => 'lei', 'position' => 'right'],
        'CZK' => ['symbol' => 'Kč', 'position' => 'right'],
        'GBP' => ['symbol' => '£', 'position' => 'left'],
    ];

    public function __construct(int $amount, string $currency) {
        $this->amount = $amount;
        $this->currency = $currency;
    }

    public function toFloat(): float
    {
        return $this->amount / 100;
    }

    public function toString(): string
    {
        return number_format($this->toFloat(), 2, '.', '') . ' ' . $this->currency;
    }

    public static function fromFloat(float $value, string $currency): MoneyDTO
    {
        return new self((int) round($value * 100), $currency);
    }

    public function toSymbolString(): string
    {
        $value = number_format($this->toFloat(), 2, ',', '');
        $currencyInfo = self::CURRENCY_SYMBOLS[$this->currency] ?? ['symbol' => $this->currency, 'position' => 'right'];

        return $currencyInfo['position'] === 'left'
            ? $currencyInfo['symbol'] . ' ' . $value
            : $value . ' ' . $currencyInfo['symbol'];
    }
} 