<?php

namespace App\Domain\Shared\Services;

class PlatformFeeService
{
    /**
     * Get the platform service fee percentage (from env only — not editable by any user).
     */
    public function getPercentage(): float
    {
        return (float) env('PLATFORM_SERVICE_FEE_PERCENT', 3);
    }

    /**
     * Calculate service fee in piasters for a given subtotal (after discount, before fee).
     */
    public function calculate(int $amountPiasters): int
    {
        $percent = $this->getPercentage();

        if ($percent <= 0) {
            return 0;
        }

        return (int) round($amountPiasters * $percent / 100);
    }

    /**
     * Whether the platform fee is active.
     */
    public function isActive(): bool
    {
        return $this->getPercentage() > 0;
    }
}
