<?php

namespace App\Enums;

enum CurrencyMinorUnit: string
{
    case GBP = 'GBP';
    case EUR = 'EUR';

    /**
     * Symbol used to display the minor unit of the currency (e.g. pence, cents).
     */
    public function symbol(): string
    {
        return match ($this) {
            self::GBP => 'p',
            self::EUR => 'c',
        };
    }

    /**
     * Resolve the minor unit symbol for a currency code, or null when unknown.
     */
    public static function symbolForCode(?string $code): ?string
    {
        if ($code === null) {
            return null;
        }

        return self::tryFrom($code)?->symbol();
    }
}
