<?php
namespace Incoviba\Service;

use DateTimeImmutable;
use IntlDateFormatter;

class Format
{
    public function localDate(string $valor, ?string $format = null, bool $print = false): string
    {
        $date = new DateTimeImmutable($valor);
        $formatter = new IntlDateFormatter('es_ES');
        if ($format == null) {
            $format = "dd 'de' MMMM 'de' YYYY";
        }
        $formatter->setPattern($format);
        return $formatter->format($date);

    }
    public function number(float|string $number, int $decimal_places = 0): string
    {
        return number_format($number, $decimal_places, ',', '.');
    }
    public function percent(float|string $number, int $decimal_places = 2, bool $multiply = false): string
    {
        return "{$this->number(($multiply) ? $number * 100 : $number, $decimal_places)}%";
    }
    public function pesos(string $valor, int $decimal_places = 0): string
    {
        return "$ {$this->number($valor, $decimal_places)}";
    }
    public function ufs(string $valor, int $decimal_places = 2): string
    {
        return "{$this->number($valor, $decimal_places)} UF";
    }
}
