<?php
/**
 * Recovery Emails Schema Class.
 *
 * @package     EDD\Pro\CartRecovery\Database\Schemas
 * @copyright   Copyright (c) 2026 Sandhills Development, LLC
 * @license     https://opensource.org/licenses/gpl-2.0.php GNU Public License
 * @since       3.6.5
 */

namespace EDD\Pro\CartRecovery\Database\Schemas;

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

use EDD\Database\Schema;

/**
 * Defines the schema for abandoned cart recovery emails.
 */
final class RecoveryEmails extends Schema {

	/**
	 * Column definitions.
	 *
	 * @var array
	 */
	public $columns = array(
		array(
			'name'     => 'id',
			'type'     => 'bigint',
			'length'   => '20',
			'unsigned' => true,
			'extra'    => 'auto_increment',
			'primary'  => true,
			'sortable' => true,
		),
		array(
			'name'       => 'cart_id',
			'type'       => 'bigint',
			'length'     => '20',
			'unsigned'   => true,
			'allow_null' => false,
			'index'      => true,
		),
		array(
			'name'    => 'template_id',
			'type'    => 'varchar',
			'length'  => '255',
			'default' => '',
		),
		array(
			'name'    => 'email_subject',
			'type'    => 'varchar',
			'length'  => '255',
			'default' => '',
		),
		array(
			'name'       => 'date_sent',
			'type'       => 'datetime',
			'default'    => null,
			'allow_null' => false,
			'date_query' => true,
		),
		array(
			'name'       => 'date_opened',
			'type'       => 'datetime',
			'default'    => null,
			'allow_null' => true,
			'date_query' => true,
		),
		array(
			'name'       => 'date_clicked',
			'type'       => 'datetime',
			'default'    => null,
			'allow_null' => true,
			'date_query' => true,
		),
		array(
			'name'       => 'date_converted',
			'type'       => 'datetime',
			'default'    => null,
			'allow_null' => true,
			'date_query' => true,
		),
		array(
			'name'    => 'discount_code',
			'type'    => 'varchar',
			'length'  => '50',
			'default' => '',
		),
		array(
			'name'       => 'recovery_token',
			'type'       => 'varchar',
			'length'     => '255',
			'allow_null' => false,
			'unique'     => true,
		),
		array(
			'name'    => 'email_hash',
			'type'    => 'varchar',
			'length'  => '64',
			'default' => '',
			'index'   => true,
		),
		array(
			'name'     => 'delivery_status',
			'type'     => 'varchar',
			'length'   => '20',
			'default'  => 'pending',
			'sortable' => true,
		),
		array(
			'name'       => 'bounce_reason',
			'type'       => 'text',
			'default'    => null,
			'allow_null' => true,
		),
		array(
			'name'       => 'date_expired',
			'type'       => 'datetime',
			'default'    => null,
			'allow_null' => true,
			'date_query' => true,
		),
		array(
			'name'       => 'date_used',
			'type'       => 'datetime',
			'default'    => null,
			'allow_null' => true,
			'date_query' => true,
		),
		array(
			'name'       => 'date_created',
			'type'       => 'datetime',
			'default'    => null,
			'allow_null' => false,
			'created'    => true,
		),
		array(
			'name'       => 'date_modified',
			'type'       => 'datetime',
			'default'    => null,
			'allow_null' => false,
			'modified'   => true,
		),
	);
}
