<?php
/**
 * Plugin activation requirements and schema bootstrap.
 *
 * @package LolaCoreForBricks
 */

declare(strict_types=1);

namespace LolaCoreForBricks;

use LolaCoreForBricks\Index\IndexSchema;

/**
 * Runs on plugin activation.
 */
class Activation
{
    public static function activate(): void
    {
        // Activation runs before init — do not call translation functions here (WP 6.7+).
        if (!defined('LOLACORE_VERSION')) {
            wp_die(
                esc_html(
                    'I need LolaCore active before this addon can start. Install and activate LolaCore, then try again.'
                ),
                esc_html('LolaCore for Bricks'),
                ['back_link' => true]
            );
        }

        global $wp_version;
        if (!isset($wp_version) || version_compare((string) $wp_version, '7.0', '<')) {
            wp_die(
                esc_html(
                    'WordPress 7.0 or later is required. Update WordPress, then try activating this addon again.'
                ),
                esc_html('LolaCore for Bricks'),
                ['back_link' => true]
            );
        }

        if (!BricksEnv::isAvailable()) {
            wp_die(
                esc_html(
                    'I need the Bricks theme active on this site. Activate Bricks, then try activating this addon again.'
                ),
                esc_html('LolaCore for Bricks'),
                ['back_link' => true]
            );
        }

        if (!BricksEnv::meetsFloor()) {
            wp_die(
                esc_html(
                    'Bricks ' . BricksEnv::FLOOR_VERSION
                    . ' or newer is required. Update Bricks, then try activating this addon again.'
                ),
                esc_html('LolaCore for Bricks'),
                ['back_link' => true]
            );
        }

        IndexSchema::create();
    }
}
