<?php
/**
 * Create Influencer Invitations Table Migration.
 *
 * @package Ugcify
 */

namespace Ugcify\Database\Migrations;

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * CreateInfluencerInvitationsTable migration class.
 */
class CreateInfluencerInvitationsTable {
	/**
	 * WordPress database instance.
	 *
	 * @var \wpdb
	 */
	private $wpdb;

	/**
	 * Constructor.
	 *
	 * @param \wpdb $wpdb WordPress database instance.
	 */
	public function __construct( $wpdb ) {
		$this->wpdb = $wpdb;
	}

	/**
	 * Run migration.
	 *
	 * @return string SQL statement.
	 */
	public function run() {
		$table_name      = $this->wpdb->prefix . 'ugcify_influencer_invitations';
		$charset_collate = $this->wpdb->get_charset_collate();

		return "CREATE TABLE $table_name (
			id BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,
			email VARCHAR(255) NOT NULL,
			name VARCHAR(255) DEFAULT NULL,
			token VARCHAR(128) NOT NULL,
			status VARCHAR(20) NOT NULL DEFAULT 'pending',
			expires_at DATETIME NOT NULL,
			user_id BIGINT(20) UNSIGNED DEFAULT NULL,
			custom_message TEXT DEFAULT NULL,
			metadata LONGTEXT DEFAULT NULL,
			invited_by BIGINT(20) UNSIGNED NOT NULL,
			accepted_at DATETIME DEFAULT NULL,
			created_at DATETIME NOT NULL,
			updated_at DATETIME NOT NULL,
			PRIMARY KEY (id),
			UNIQUE KEY token (token),
			KEY email (email(191)),
			KEY status (status),
			KEY user_id (user_id)
		) $charset_collate;";
	}
}