<?php
/**
 * AddPointsBalanceColumnToMemberTableUpgrade.php.
 *
 * @package RewardsWP
 */

namespace Awesomemotive\Rewardswp\Database\Upgrades;

if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

use Awesomemotive\Rewardswp\Abstracts\AbstractDatabaseUpgrade;
use Awesomemotive\Rewardswp\Database\Tables\MembersTable;

/**
 * Class AddPointsBalanceColumnToMemberTableUpgrade.
 */
class AddPointsBalanceColumnToMemberTableUpgrade extends AbstractDatabaseUpgrade {
	/**
	 * Upgrade target version.
	 *
	 * @var string
	 */
	protected string $version = '1.1.0';

	/**
	 * Members table instance.
	 *
	 * @since 1.0.1
	 *
	 * @var MembersTable
	 */
	private MembersTable $table;

	/**
	 * Constructor.
	 *
	 * @since 1.0.1
	 *
	 * @param MembersTable $table Members table instance.
	 */
	public function __construct( MembersTable $table ) {
		$this->table = $table;
	}

	/**
	 * Run the upgrade.
	 *
	 * @since 1.0.0
	 *
	 * @return void
	 */
	public function up(): void {
		$this->table->add_column(
			$this->table->get_prefixed_table_name(),
			'points_balance',
			'int(11) NOT NULL DEFAULT 0',
			'completed_referrals'
		);
	}
}
