<?php

declare(strict_types=1);

namespace Australcode\Rewards\Infrastructure\Database;

defined( 'ABSPATH' ) || exit;

/**
 * Single source of truth for custom table names. Any code that iterates tables
 * (uninstall, health checks, maintenance) must use allTables().
 *
 * Phase 0 ships the two foundational tables + the migration control table.
 * Future migrations (M0002+) add: earning_rules, redemption_rules, tiers,
 * referrals, campaigns. See docs/architecture.md.
 */
final class Schema {

	public const TABLE_BALANCES         = 'acrwd_balances';
	public const TABLE_TRANSACTIONS     = 'acrwd_transactions';
	public const TABLE_TIERS            = 'acrwd_tiers';
	public const TABLE_CAMPAIGNS        = 'acrwd_campaigns';
	public const TABLE_REFERRALS        = 'acrwd_referrals';
	public const TABLE_EARNING_RULES    = 'acrwd_earning_rules';
	public const TABLE_REDEMPTION_RULES = 'acrwd_redemption_rules';
	public const TABLE_MIGRATIONS       = 'acrwd_migrations';

	/**
	 * Resolve a logical table key to its prefixed physical name.
	 */
	public static function table_name( string $table ): string {
		global $wpdb;
		return $wpdb->prefix . $table;
	}

	/**
	 * @return string[] Logical table keys (unprefixed).
	 */
	public static function all_tables(): array {
		return array(
			self::TABLE_BALANCES,
			self::TABLE_TRANSACTIONS,
			self::TABLE_TIERS,
			self::TABLE_CAMPAIGNS,
			self::TABLE_REFERRALS,
			self::TABLE_EARNING_RULES,
			self::TABLE_REDEMPTION_RULES,
			self::TABLE_MIGRATIONS,
		);
	}
}
