<?php
/**
 * Recovery Cart Query Class.
 *
 * @package     EDD\Pro\CartRecovery\Database\Queries
 * @copyright   Copyright (c) 2025, Easy Digital Downloads, LLC
 * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       3.6.5
 */

namespace EDD\Pro\CartRecovery\Database\Queries;

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit; // @codeCoverageIgnore

use EDD\Database\Query;

/**
 * Class used for querying recovery carts.
 *
 * @since 3.6.5
 *
 * @see \EDD\Pro\CartRecovery\Database\Queries\RecoveryCart::__construct() for accepted arguments.
 */
class RecoveryCart extends Query {

	/** Table Properties ******************************************************/

	/**
	 * Name of the database table to query.
	 *
	 * @var string
	 */
	protected $table_name = 'acr_carts';

	/**
	 * String used to alias the database table in MySQL statement.
	 *
	 * @var string
	 */
	protected $table_alias = 'acr';

	/**
	 * Name of class used to setup the database schema
	 *
	 * @var string
	 */
	protected $table_schema = '\\EDD\\Pro\\CartRecovery\\Database\\Schemas\\RecoveryCarts';

	/** Item ******************************************************************/

	/**
	 * Name for a single item
	 *
	 * @var string
	 */
	protected $item_name = 'abandoned_cart';

	/**
	 * Plural version for a group of items.
	 *
	 * @var string
	 */
	protected $item_name_plural = 'abandoned_carts';

	/**
	 * Callback function for turning IDs into objects
	 *
	 * @var mixed
	 */
	protected $item_shape = '\\EDD\\Pro\\CartRecovery\\Carts\\Cart';

	/** Cache *****************************************************************/

	/**
	 * Group to cache queries and queried items in.
	 *
	 * @var string
	 */
	protected $cache_group = 'acr_carts';

	/**
	 * Override default ordering to favour recent updates.
	 *
	 * @since 3.6.1
	 */
	protected function set_query_var_defaults() {
		parent::set_query_var_defaults();

		$this->query_var_defaults['orderby'] = 'date_modified';
		$this->query_var_defaults['order']   = 'DESC';
	}
}
