<?php

namespace App\Domain\Financial\Enums;

/**
 * How one line of a routing rule takes its share.
 *
 * Applied strictly in this order — fixed, then percentage, then remainder —
 * because that is the only order in which "5 جنيه رسوم قيد، و10% إدارة،
 * والباقي تدريب" means what an accountant reads it to mean.
 */
enum AllocationType: string
{
    /** A flat number of piasters off the top. */
    case Fixed = 'fixed';

    /** A percentage of the net revenue, in basis points (1400 = 14.00%). */
    case Percentage = 'percentage';

    /** Everything the lines above did not take. At most one per rule. */
    case Remainder = 'remainder';

    public function label(): string
    {
        return match ($this) {
            self::Fixed => 'مبلغ ثابت',
            self::Percentage => 'نسبة مئوية',
            self::Remainder => 'الباقي',
        };
    }

    public function hint(): string
    {
        return match ($this) {
            self::Fixed => 'يُخصم من أعلى المبلغ قبل النسب',
            self::Percentage => 'نسبة من صافي الإيراد بعد الضريبة',
            self::Remainder => 'كل ما تبقى بعد السطور السابقة — سطر واحد فقط لكل قاعدة',
        };
    }

    /** Fixed first, then percentage, then remainder. Lower runs earlier. */
    public function pass(): int
    {
        return match ($this) {
            self::Fixed => 0,
            self::Percentage => 1,
            self::Remainder => 2,
        };
    }
}
