<?php
/**
 * Plugin Name:      StoreAgent AI for WooCommerce
 * Requires Plugins: woocommerce
 * Plugin URI:       https://storeagent.ai/
 * Description:      StoreAgent AI for WooCommerce adds AI powered features to your WooCommerce store.
 * Version:          1.1.5
 * Author:           Rymera Web Co
 * Author URI:       https://rymera.com.au/
 * License: GPL      v2 or later
 * Text Domain:      storeagent-ai-for-woocommerce
 * Domain Path:      /languages
 *
 * @package  SAAI
 * @author   Rymera Web Co <info@rymera.com.au>
 * @license  GPL v2 or later
 * @link     https://rymera.com.au/
 */

/***************************************************************************
 * Main plugin file
 * **************************************************************************
 *
 * This file is the main entry point for the plugin. It is responsible for
 * loading the plugin's dependencies and initializing the plugin.
 */

/***************************************************************************
 * Ensure that the plugin is not accessed or called directly
 * **************************************************************************
 */

defined( 'ABSPATH' ) || exit;

/***************************************************************************
 * Plugin Constants
 * **************************************************************************
 */

/**
 * Plugin file path.
 */
define( 'SAAI_PLUGIN_FILE', __FILE__ );

/**
 * Plugin version.
 *
 * Hardcoded to avoid calling get_plugin_data() at load time, which uses
 * file_get_contents() internally and fails on LiteSpeed servers.
 *
 * @see https://github.com/Rymera-Web-Co/storeagent-ai-for-woocommerce/issues/402
 */
define( 'SAAI_VERSION', '1.1.5' );

/**
 * Plugin version key.
 */
define( 'SAAI_INSTALLED_VERSION', 'saai_installed_version' );

/**
 * Plugin directory path.
 */
define( 'SAAI_PLUGIN_DIR_PATH', plugin_dir_path( __FILE__ ) );

/**
 * Templates directory path.
 */
define( 'SAAI_TEMPLATES_DIR', SAAI_PLUGIN_DIR_PATH . 'templates/' );

/**
 * Plugin URL.
 */
define( 'SAAI_PLUGIN_URL', plugin_dir_url( __FILE__ ) );

/**
 * Plugin basename.
 */
define( 'SAAI_BASENAME', plugin_basename( __FILE__ ) );

/***************************************************************************
 * Loads plugin text domain.
 * **************************************************************************
 *
 * Loads the plugin text domain for translation.
 */
function saai_textdomain() {

    load_plugin_textdomain(
        'storeagent-ai-for-woocommerce',
        false,
        dirname( plugin_basename( __FILE__ ) ) . '/languages'
    );
}

add_action( 'init', 'saai_textdomain' );

/***************************************************************************
 * Checks required minimum PHP version to run the plugin.
 ***************************************************************************
 *
 * Checks the required minimum PHP version to run the plugin and prints
 * admin notice for admins if the PHP version is not met.
 */
if ( version_compare( PHP_VERSION, '7.4', '<' ) ) {
    /**
     * Admin notice for required PHP version to run the plugin
     */
    function saai_required_php_version() {

        include SAAI_PLUGIN_DIR_PATH . 'templates/admin/parts/require-php-version.php';
    }

    add_action( 'admin_notices', 'saai_required_php_version' );
} else {

    /***************************************************************************
     * Loads the plugin.
     ***************************************************************************
     *
     * Here we load the plugin if all checks passed.
     */

    /**
     * Our bootstrap class instance.
     *
     * @var SAAI\App $app
     */
    $app = require_once 'bootstrap/App.php';

    $app->boot();
}
