<?php

namespace App\Modules\Sales\Services;

use App\Modules\Sales\Exceptions\SalesOperationalException;
use App\Modules\Sales\Models\SalesOrder;
use App\Modules\Sales\Support\SalesOrderLifecycleStatus;

final class SalesOrderStatusParser
{
    public static function fromOrder(SalesOrder $order): SalesOrderLifecycleStatus
    {
        $s = SalesOrderLifecycleStatus::tryFrom((string) $order->status);
        if ($s === null) {
            throw new SalesOperationalException('Unknown sales order status.', 'sales_unknown_status');
        }

        return $s;
    }
}
