<?php
/**
 * Recovery Emails Table.
 *
 * @package     EDD\Pro\CartRecovery\Database\Tables
 * @since       3.6.0
 */

namespace EDD\Pro\CartRecovery\Database\Tables;

use EDD\Database\Table;

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

/**
 * Registers the edd_acr_emails table.
 */
final class RecoveryEmails extends Table {

	/**
	 * Table name (without prefix).
	 *
	 * @var string
	 */
	protected $name = 'acr_emails';

	/**
	 * Database version.
	 *
	 * @var int
	 */
	protected $version = 202601090;

	/**
	 * Upgrade routines.
	 *
	 * @var array
	 */
	protected $upgrades = array();

	/**
	 * Set the table schema.
	 */
	protected function set_schema() {
		$this->schema = "id bigint(20) unsigned NOT NULL auto_increment,
			cart_id bigint(20) unsigned NOT NULL,
			template_id varchar(255) NOT NULL default '',
			email_subject varchar(255) NOT NULL default '',
			date_sent datetime NOT NULL,
			date_opened datetime default NULL,
			date_clicked datetime default NULL,
			date_converted datetime default NULL,
			discount_code varchar(50) NOT NULL default '',
			recovery_token varchar(255) NOT NULL,
			email_hash varchar(64) NOT NULL default '',
			delivery_status varchar(20) NOT NULL default 'pending',
			date_expired datetime NULL DEFAULT NULL,
			date_used datetime NULL DEFAULT NULL,
			bounce_reason text,
			date_created datetime NOT NULL default CURRENT_TIMESTAMP,
			date_modified datetime NOT NULL default CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
			PRIMARY KEY  (id),
			UNIQUE KEY recovery_token (recovery_token),
			KEY cart_id (cart_id),
			KEY email_hash (email_hash),
			KEY date_sent (date_sent),
			KEY delivery_status (delivery_status),
			KEY date_expired (date_expired),
			KEY bounce_reason (bounce_reason(100))
		";
	}
}
