<?php
/**
 * BookiFlex Core
 *
 * @package    BookiFlex
 * @subpackage Core
 * @author     BookiFlex
 * @copyright  Copyright (c) 2025 BookiFlex
 * @license    GPL-2.0-or-later
 *
 * @link       https://bookiflex.com
 */

declare(strict_types=1);

namespace BookiFlex\Core\Admin\Lifecycle;

use BookiFlex\Core\Contract\ExtensionActivatorInterface;
use BookiFlex\Core\Provider\LocalTimeZone;

defined('ABSPATH') || exit;

/**
 * Base class for extension activators
 *
 * Provides default (empty) implementations for all interface methods.
 * Extensions can override only the methods they need.
 */
abstract class AbstractExtensionActivator implements ExtensionActivatorInterface
{
	/**
	 * @inheritDoc
	 */
	public function getSchemas(): array
	{
		return [];
	}

	/**
	 * @inheritDoc
	 */
	public function install(): void
	{
		// Default: no installation logic
	}

	/**
	 * @inheritDoc
	 */
	public function uninstall(): void
	{
		// Default: no uninstallation logic
	}

	/**
	 * @inheritDoc
	 */
	public function enableRuntimeResources(): void
	{
		// Default: no runtime resources
	}

	/**
	 * @inheritDoc
	 */
	public function disableRuntimeResources(): void
	{
		// Default: no runtime resources
	}

	/**
	 * Returns the next occurrence of the given time in the site's timezone.
	 * Pass to scheduleRecurring() as $startAt to defer the first run to night.
	 */
	protected static function nextNightTime(int $hour = 3, int $minute = 0): \DateTimeImmutable
	{
		$tz     = LocalTimeZone::get();
		$now    = new \DateTimeImmutable('now', $tz);
		$target = $now->setTime($hour, $minute, 0);

		if ($target <= $now) {
			$target = $target->modify('+1 day');
		}

		return $target;
	}
}
