<?php
/**
 * Plugin Name: Nemtly Booking – Events, Appointments & Booking Calendar
 * Plugin URI: https://github.com/sapayth/nemtly-booking
 * Description: Book appointments and events 24/7 with Stripe payments, Google Calendar sync, reminders, and a customer dashboard.
 * Version: 2.3.0
 * Author: Sapayth Hossain
 * Author URI: https://sapayth.com
 * Text Domain: nemtly-booking
 * Domain Path: /languages
 * License: GPLv2 or later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Requires at least: 5.8
 * Requires PHP: 7.4
 *
 * @package Nemtly Booking
 */

// If this file is called directly, abort.
if ( ! defined( 'WPINC' ) ) {
    die;
}

// Plugin constants
define( 'NEMTLY_BOOKING_FILE', __FILE__ );

// Composer autoloader
if ( ! file_exists( plugin_dir_path( __FILE__ ) . 'vendor/autoload.php' ) ) {
    // Composer dependencies not installed — show an admin notice so the site admin knows why
    add_action(
        'admin_notices',
        function () {
            if ( ! current_user_can( 'activate_plugins' ) ) {
                return;
            }
            ?>
            <div class="notice notice-error is-dismissible">
                <p><?php echo esc_html__( 'Nemtly Booking dependencies are missing. Run `composer install` in the plugin directory or install a packaged release that includes vendor dependencies.', 'nemtly-booking' ); ?></p>
            </div>
            <?php
        }
    );

    return; // stop bootstrap until dependencies are installed
}

require_once plugin_dir_path( __FILE__ ) . 'vendor/autoload.php';

// Load database constants
require_once plugin_dir_path( __FILE__ ) . 'includes/Core/DB_Constants.php';

/**
 * Initialize the plugin
 */
function nemtly_init() {
    // Initialize the main plugin class
    NemtlyBooking\Core\Plugin::get_instance();
}

// Run the plugin
nemtly_init();

// Register WP-CLI commands when available.
if ( defined( 'WP_CLI' ) && WP_CLI ) {
    \WP_CLI::add_command(
        'nemtly seed',
        function () {
			\WP_CLI::log( 'Seeding Nemtly Booking demo data…' );

			$summary = \NemtlyBooking\Core\Seeder::run();

			\WP_CLI::success(
                sprintf(
                    'Done! Created %d categories, %d tags, %d events, %d bookings, %d payments.',
                    $summary['categories'],
                    $summary['tags'],
                    $summary['events'],
                    $summary['bookings'],
                    $summary['payments']
                )
			);
		}
    );

    \WP_CLI::add_command(
        'nemtly reset',
        function () {
			\WP_CLI::confirm( 'This will delete ALL events, bookings, payments, and taxonomy terms. Continue?' );

			$summary = \NemtlyBooking\Core\Seeder::reset();

			\WP_CLI::success(
                sprintf(
                    'Reset complete. Removed %d events.',
                    $summary['events_deleted']
                )
			);
		}
    );
}
