<?php

namespace Licenzo\Modules\EDD;

if (!defined('ABSPATH')) {
    exit;
}

class EddOrderHandler
{
    public function handle(): void
    {
        add_action('edd_complete_purchase', [$this, 'process'], 10, 1);
        add_action('edd_transition_order_status', [$this, 'syncStatus'], 10, 3);
    }

    public function process($paymentId): void
    {
        if (!$paymentId) {
            return;
        }
        (new EddOrderService())->process((int)$paymentId);
    }

    public function syncStatus($orderId, $fromStatus, $toStatus): void
    {
        if (!$orderId) {
            return;
        }
        (new EddOrderService())->syncOrderStatus((int)$orderId, (string)$fromStatus, (string)$toStatus);
    }
}
