<?php
/**
 * BookiFlex Cart Extension
 *
 * @package    BookiFlex
 * @subpackage Cart
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Extensions\Cart\Service\Jobs;

use BookiFlex\Core\Contract\Queue\QueueJobInterface;
use BookiFlex\Extensions\Cart\Service\CartService;

defined('ABSPATH') || exit;

/**
 * Queue job for marking expired carts as abandoned.
 *
 * Runs monthly and calls CartService::cleanupExpiredCarts() to transition
 * pending/checkout carts older than 3 days into abandoned status.
 */
class CleanupExpiredCartsJob implements QueueJobInterface
{
    public const HOOK = 'bookiflex_cart_cleanup_monthly';

    public function __construct(
        private readonly CartService $cartService
    ) {
    }

    public function handle(array $args): void
    {
        $this->cartService->cleanupExpiredCarts();
    }

    public function getHook(): string
    {
        return self::HOOK;
    }

    public function getMaxAttempts(): int
    {
        return 3;
    }
}
