<?php

declare (strict_types=1);
namespace DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Checkout;

use DropshippingExportFreeVendor\WPDesk\Library\DropshippingExport\Service\Ucp\Checkout\State\CheckoutStateRepository;
/**
 * Resolves the current status of a UCP checkout session.
 */
final class CheckoutStatusResolver
{
    private CheckoutStateRepository $state;
    private CheckoutOrderFinder $order_finder;
    public function __construct(CheckoutStateRepository $state, CheckoutOrderFinder $order_finder)
    {
        $this->state = $state;
        $this->order_finder = $order_finder;
    }
    public function get_status(string $session_id): string
    {
        if ($this->state->is_canceled()) {
            return 'canceled';
        }
        $order = $this->order_finder->find_by_checkout_id($session_id);
        if (null !== $order) {
            return 'completed';
        }
        // Check for stored violations (from last Create/Update).
        if ($this->state->has_violations()) {
            return 'requires_escalation';
        }
        return 'ready_for_complete';
    }
}
