<?php

declare(strict_types=1);

namespace Australcode\Rewards;

use Australcode\Rewards\Infrastructure\Database\Migrator;

defined( 'ABSPATH' ) || exit;

/**
 * Runs on plugin activation. Migrations are idempotent, so running them here
 * (and again on boot via maybe_run_pending_migrations) is safe.
 */
final class Activator {

	public static function activate(): void {
		Plugin::instance()->container()->get( Migrator::class )->migrate();
		update_option( 'acrwd_installed_version', ACRWD_VERSION, false );

		// Defer the rewrite flush to the next init, once the My Account endpoint
		// is registered (it may not exist yet in the activation request).
		update_option( 'acrwd_flush_rewrite', '1', false );
		flush_rewrite_rules();
	}
}
