<?php
/**
 * Plugin Name: SeekMake - Instant 3D Printing Quote Plugin on your Website
 * Description: Let customers upload STL files and get instant 3D printing prices on your website. Automate quoting, orders, and payments with SeekMake AI.
 * Version: 1.2.4
 * Author: SeekMake
 * Author URI: https://seekmake.com
 * License: GPL v2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: seekmake
 * Domain Path: /languages
 * Requires at least: 5.0
 * Tested up to: 6.9
 * Requires PHP: 7.4
 */

if (!defined('WPINC')) {
    die;
}

define('SEEKMAKE_VERSION', '1.2.4');
define('SEEKMAKE_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('SEEKMAKE_PLUGIN_URL', plugin_dir_url(__FILE__));
define('SEEKMAKE_PLUGIN_BASENAME', plugin_basename(__FILE__));

define('SEEKMAKE_API_URL', 'https://seekmake.com');
define('SEEKMAKE_DASHBOARD_URL', 'https://seekmake.com/dashboard/manufacturer/job-board/quotes');
define('SEEKMAKE_AUTH_URL', 'https://seekmake.com/auth/login');
define('SEEKMAKE_LOGOUT_URL', 'https://seekmake.com/auth/logout?isEmbed=true');

function seekmake_core_maybe_upgrade() {
    $stored_version = get_option('seekmake_plugin_version', '0');

    if (version_compare($stored_version, SEEKMAKE_VERSION, '<')) {
        if (version_compare($stored_version, '1.2.1', '<')) {
            $is_authenticated = get_option('seekmake_authenticated', false);
            if ($is_authenticated) {
                $active_plugins = get_option('seekmake_active_plugins', array());
                if (!in_array('Astra AI', $active_plugins)) {
                    $active_plugins[] = 'Astra AI';
                    update_option('seekmake_active_plugins', $active_plugins);
                }
            }
        }

        update_option('seekmake_plugin_version', SEEKMAKE_VERSION);
    }
}
add_action('admin_init', 'seekmake_core_maybe_upgrade');

function seekmake_core_activate_plugin() {
    require_once SEEKMAKE_PLUGIN_DIR . 'includes/class-seekmake-activator.php';
    SeekMake_Activator::activate();
}

function seekmake_core_deactivate_plugin() {
    require_once SEEKMAKE_PLUGIN_DIR . 'includes/class-seekmake-deactivator.php';
    SeekMake_Deactivator::deactivate();
}

register_activation_hook(__FILE__, 'seekmake_core_activate_plugin');
register_deactivation_hook(__FILE__, 'seekmake_core_deactivate_plugin');

require SEEKMAKE_PLUGIN_DIR . 'includes/class-seekmake.php';

function seekmake_core_run_plugin() {
    $plugin = new SeekMake();
    $plugin->run();
}

seekmake_core_run_plugin();
