<?php

namespace App\Services\Coin;

class CoinService
{
    /**
     * Calculate the total coins for points or score.
     */
    public static function calculateCoinsFromPoints(int $points): int
    {
        $scoreRatio = config('application_info.coins.score_ratio');

        if ($points <= 0) {
            return 0; // No coins for zero or negative points
        }

        return round($points / $scoreRatio['score']);
    }

    /**
     * Calculate the total coins for USD.
     */
    public static function calculateCoinsFromUSD(float $usd): int
    {
        $scoreRatio = config('application_info.coins.usd_ratio');

        if ($usd <= 0) {
            return 0; // No coins for zero or negative USD
        }

        // if the USD has a decimal part, we round it to the nearest integer
        $usd = round($usd);

        return (int) ($scoreRatio['coin'] * $usd);
    }

    public static function getUSDFromCoins(int $coins): float
    {
        $scoreRatio = config('application_info.coins.usd_ratio');

        return (float) $coins / $scoreRatio['coin'];
    }
}
