<?php

namespace App\Domain\Financial\Enums;

/**
 * How tax is carried on a revenue source.
 *
 * The distinction that matters, and the one that gets ERPs failed in an audit:
 * VAT is **not** a slice of revenue. It is money collected on behalf of the Tax
 * Authority and owed to it, so it credits a liability account, never a revenue
 * one. The routing rule therefore takes the tax out first and splits only what
 * is left.
 *
 * Egypt's standard VAT rate is 14%; some services sit at the 10% schedule rate
 * and some are exempt outright, which is exactly why this is a per-source
 * setting and not one switch for the whole academy.
 */
enum TaxMode: string
{
    /** Exempt or out of scope. Everything collected is revenue. */
    case None = 'none';

    /**
     * The price already contains the tax. 114 collected at 14% is 100 revenue
     * and 14 owed to the Authority — the customer paid one number.
     */
    case Inclusive = 'inclusive';

    /**
     * The tax is a separate line the invoice already carries, added on top of
     * the price. The rule posts the invoice's own tax figure and routes the
     * rest; it never invents tax that was not charged.
     */
    case Exclusive = 'exclusive';

    public function label(): string
    {
        return match ($this) {
            self::None => 'بدون ضريبة',
            self::Inclusive => 'السعر شامل الضريبة',
            self::Exclusive => 'الضريبة مضافة على السعر',
        };
    }

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

    public function chargesTax(): bool
    {
        return $this !== self::None;
    }
}
