<?php
/**
 * Plugin Name:       Proto Preview — InVision Prototyping & Client Review Hub
 * Plugin URI:        https://bowdenworks.com
 * Description:       Native WordPress Custom Post Types, Taxonomies, and InVision-style Prototype Player for web designers and client review workflows.
 * Version:           2.0.0
 * Author:            Bowden Works
 * Author URI:        https://bowdenworks.com
 * License:           GPL-2.0+
 * Text Domain:       proto-preview
 * Domain Path:       /languages
 */

if (!defined('ABSPATH')) {
    exit;
}

define('PROTO_PREVIEW_VERSION', '2.0.0');
define('PROTO_PREVIEW_PLUGIN_DIR', plugin_dir_path(__FILE__));
define('PROTO_PREVIEW_PLUGIN_URL', plugin_dir_url(__FILE__));

require_once PROTO_PREVIEW_PLUGIN_DIR . 'includes/class-proto-activator.php';
require_once PROTO_PREVIEW_PLUGIN_DIR . 'includes/class-proto-cpt.php';
require_once PROTO_PREVIEW_PLUGIN_DIR . 'includes/class-proto-meta-boxes.php';
require_once PROTO_PREVIEW_PLUGIN_DIR . 'includes/class-proto-columns.php';
require_once PROTO_PREVIEW_PLUGIN_DIR . 'includes/class-proto-notifications.php';
require_once PROTO_PREVIEW_PLUGIN_DIR . 'includes/class-proto-rest.php';
require_once PROTO_PREVIEW_PLUGIN_DIR . 'includes/class-proto-player.php';

/**
 * Activation Hook — Seeds native CPTs, Taxonomies, and demo content
 */
function proto_preview_activate() {
    // 1. Register Post Types and Taxonomies so terms can be inserted
    $cpt = new Proto_Preview_CPT();
    $cpt->register_post_types();
    $cpt->register_taxonomies();

    // 2. Create custom tables for vector comments and approvals if needed
    require_once PROTO_PREVIEW_PLUGIN_DIR . 'includes/class-proto-activator.php';
    Proto_Preview_Activator::activate();

    // 3. Seed demo CPT projects
    $cpt->seed_demo_projects();

    // 4. Flush rewrite rules
    flush_rewrite_rules();
}

/**
 * Deactivation Hook
 */
function proto_preview_deactivate() {
    flush_rewrite_rules();
}

register_activation_hook(__FILE__, 'proto_preview_activate');
register_deactivation_hook(__FILE__, 'proto_preview_deactivate');

/**
 * Initialize Plugin Components
 */
function proto_preview_init() {
    // 0. Ensure Database Tables are up-to-date
    Proto_Preview_Activator::upgrade_tables();

    // 1. Custom Post Types & Taxonomies
    $cpt = new Proto_Preview_CPT();
    $cpt->init();

    // 2. Custom Meta Boxes & Post Editor UI
    if (is_admin()) {
        $meta_boxes = new Proto_Preview_Meta_Boxes();
        $meta_boxes->init();

        $columns = new Proto_Preview_Columns();
        $columns->init();
    }

    // 3. REST API for Pin Comments & Approvals
    $rest = new Proto_Preview_REST();
    $rest->init();

    // 4. InVision Player / Template Loader
    $player = new Proto_Preview_Player();
    $player->init();
}

add_action('plugins_loaded', 'proto_preview_init');
