<?php

namespace App\Modules\Sales\Support;

use App\Modules\Inventory\Stock\Support\DecimalQuantity;
use App\Modules\Sales\Models\SalesOrderLine;

final class SalesOrderLineUiLabels
{
    public static function allocationStateKey(SalesOrderLine $line): string
    {
        $ordered = trim((string) $line->quantity_ordered);
        $reserved = trim((string) $line->quantity_reserved);
        $fulfilled = trim((string) $line->quantity_fulfilled);
        $covered = DecimalQuantity::add($reserved, $fulfilled);
        if (DecimalQuantity::gte($covered, $ordered)) {
            return 'complete';
        }
        if (DecimalQuantity::gtZero($reserved)) {
            return 'partial';
        }

        return 'none';
    }

    public static function fulfillmentStateKey(SalesOrderLine $line): string
    {
        $ordered = trim((string) $line->quantity_ordered);
        $fulfilled = trim((string) $line->quantity_fulfilled);
        if (DecimalQuantity::gte($fulfilled, $ordered)) {
            return 'complete';
        }
        if (DecimalQuantity::gtZero($fulfilled)) {
            return 'partial';
        }

        return 'none';
    }
}
