<?php

namespace App\Domain\Shared\Services;

class PlatformFeeService
{
    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);
    }

    public function isActive(): bool
    {
        return $this->getPercentage() > 0;
    }

    /**
     * Whether the customer pays the fee (added to their total) or the academy absorbs it.
     * true = customer pays (default), false = academy absorbs (deducted from academy revenue).
     */
    public function customerPays(): bool
    {
        return (bool) app(SettingsService::class)->get('platform_fee_customer_pays', false);
    }
}
