<?php
/**
 * ANCP Core - public facade.
 *
 * The booted core API surface. Today it exposes the running core version and
 * thin pass-throughs to the table map and schema; it is the seam where the
 * later core services (privacy, date, place, phonetic, GEDCOM) will attach
 * (spec-00 Section 6). Instantiated once by Loader::boot().
 *
 * @package AncestorPress\Core
 * @since   0.1.0
 */

namespace AncestorPress\Core;

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

/**
 * Core facade.
 *
 * @since 0.1.0
 */
class Core {

	/**
	 * The booted core version.
	 *
	 * @var string|null
	 */
	private static $version = null;

	/**
	 * Initialise the booted core. Called once by the loader.
	 *
	 * @since  0.1.0
	 * @param  string $version The winning core version.
	 * @return void
	 */
	public static function init( $version ) {
		self::$version = $version;
	}

	/**
	 * The running core version.
	 *
	 * @since  0.1.0
	 * @return string|null
	 */
	public static function version() {
		return self::$version;
	}

	/**
	 * Physical name of a core table (pass-through to the table map).
	 *
	 * @since  0.1.0
	 * @param  string $key Logical table key.
	 * @return string
	 */
	public static function table( $key ) {
		return Table_Map::name( $key );
	}

	/**
	 * Create/upgrade core tables (pass-through to the schema owner).
	 *
	 * @since  0.1.0
	 * @return void
	 */
	public static function install_schema() {
		Schema::install();
	}

	/**
	 * Run the prefix rename migration if needed (pass-through to the migrator).
	 *
	 * @since  0.2.0
	 * @return array Migration result (see Migrator::maybe_migrate()).
	 */
	public static function migrate_prefix() {
		return Migrator::maybe_migrate();
	}
}

