<?php

namespace App\Modules\Sales\Services;

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

final class SalesLineRemainingCalculator
{
    public static function allocatableRemaining(SalesOrderLine $line): string
    {
        $ordered = trim((string) $line->quantity_ordered);
        $reserved = trim((string) $line->quantity_reserved);
        $fulfilled = trim((string) $line->quantity_fulfilled);

        $committed = DecimalQuantity::add($fulfilled, $reserved);

        return DecimalQuantity::add($ordered, DecimalQuantity::negate($committed));
    }

    public static function fulfillableFromReservation(SalesOrderLine $line): string
    {
        return trim((string) $line->quantity_reserved);
    }
}
