<?php

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

use WC_Session_Handler;
/**
 * Manages UCP checkout state persistence in the WooCommerce session.
 */
final class CheckoutStateRepository
{
    private const ACTIVE_KEY = 'ucp_session_active';
    private const STATUS_KEY = 'ucp_status';
    private const VIOLATIONS_KEY = 'ucp_violations';
    private const PAYMENT_LOCK_KEY = 'ucp_payment_lock';
    private const COMPLETED_ORDER_ID_KEY = 'ucp_completed_order_id';
    public function exists(): bool
    {
        return \WC()->session ? (bool) \WC()->session->get(self::ACTIVE_KEY) : \false;
    }
    public function mark_active(): void
    {
        if (\WC()->session) {
            \WC()->session->set(self::ACTIVE_KEY, \true);
        }
    }
    public function lock_payment(): void
    {
        if (!\WC()->session instanceof WC_Session_Handler) {
            return;
        }
        \WC()->session->set(self::PAYMENT_LOCK_KEY, \true);
        \WC()->session->save_data();
    }
    public function unlock_payment(): void
    {
        if (!\WC()->session instanceof WC_Session_Handler) {
            return;
        }
        \WC()->session->set(self::PAYMENT_LOCK_KEY, \false);
        \WC()->session->save_data();
    }
    public function mark_completed(int $order_id): void
    {
        if (\WC()->session) {
            \WC()->session->set(self::COMPLETED_ORDER_ID_KEY, $order_id);
        }
    }
    public function is_canceled(): bool
    {
        return \WC()->session ? 'canceled' === \WC()->session->get(self::STATUS_KEY) : \false;
    }
    public function mark_canceled(): void
    {
        if (\WC()->session) {
            \WC()->session->set(self::STATUS_KEY, 'canceled');
        }
    }
    public function set_has_violations(bool $has_violations): void
    {
        if (\WC()->session) {
            \WC()->session->set(self::VIOLATIONS_KEY, $has_violations);
        }
    }
    public function has_violations(): bool
    {
        return \WC()->session ? (bool) \WC()->session->get(self::VIOLATIONS_KEY) : \false;
    }
}
