<?php

namespace App\Support;

use Carbon\Carbon;

class CreditHelper
{
    /**
     * Devuelve la fecha en formato 'd/m/Y'
     */
    public static function formatDate(?string $date): ?string
    {
        if (! $date) {
            return null;
        }

        return Carbon::parse($date)->format('d/m/Y');
    }

    /**
     * Devuelve el porcentaje formateado ("20.00%")
     */
    public static function formatPercent(float $value): string
    {
        return number_format($value, 2).'%';
    }

    /**
     * Devuelve un valor monetario formateado ("$ 1,200,000.00")
     */
    public static function formatMoney(float $value): string
    {
        return '$ '.number_format($value, 2, '.', ',');
    }

    /**
     * Devuelve "Cuota X/Y"
     */
    public static function formatInstallmentLabel(int $number, int $total): string
    {
        return "Cuota {$number}/{$total}";
    }

    /**
     * Calcula días entre fechas
     */
    public static function daysBetween(string $from, string $to): int
    {
        return (int) Carbon::parse($from)->diffInDays(Carbon::parse($to));
    }

    /**
     * Determina si una fecha está vencida
     */
    public static function isOverdue(string $date): bool
    {
        return Carbon::parse($date)->lt(Carbon::today());
    }

    /**
     * Determina si la fecha es hoy
     */
    public static function isToday(string $date): bool
    {
        return Carbon::parse($date)->isToday();
    }
}
