<?php

declare(strict_types=1);

namespace App\Enums;

use Filament\Support\Contracts\HasLabel;

/**
 * Periodicidad de pagos para créditos.
 *
 * Implementa HasLabel para compatibilidad con Filament 4.1
 * (Select::options(), Infolists, etc.)
 */
enum Periodicity: string implements HasLabel
{
    case DAILY = 'daily';
    case WEEKLY = 'weekly';
    case BIWEEKLY = 'biweekly';
    case MONTHLY = 'monthly';

    /**
     * Etiqueta legible para UI (requerido por Filament HasLabel).
     */
    public function getLabel(): string
    {
        return match ($this) {
            self::DAILY => 'Diario',
            self::WEEKLY => 'Semanal',
            self::BIWEEKLY => 'Quincenal',
            self::MONTHLY => 'Mensual',
        };
    }

    /**
     * Obtiene el número de días entre pagos.
     */
    public function getDaysInterval(): int
    {
        return match ($this) {
            self::DAILY => 1,
            self::WEEKLY => 7,
            self::BIWEEKLY => 14,
            self::MONTHLY => 30,
        };
    }

    /**
     * Obtiene el número aproximado de cuotas por mes.
     */
    public function getInstallmentsPerMonth(): float
    {
        return match ($this) {
            self::DAILY => 30.0,
            self::WEEKLY => 4.0,
            self::BIWEEKLY => 2.0,
            self::MONTHLY => 1.0,
        };
    }
}
