<?php

/**
 * Tutorial Manager for Content Craft AI
 * 
 * Handles tracking tutorial status for new users
 */

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

class ContentCraftAI_TutorialManager
{
  // Option name to store tutorial status
  const TUTORIAL_STATUS_OPTION = 'content_craft_ai_tutorial_status';

  /**
   * Initialize tutorial tracking
   */
  public static function init()
  {
    // Create option if it doesn't exist
    if (!get_option(self::TUTORIAL_STATUS_OPTION)) {
      self::set_tutorial_status(array(
        'installation_date' => current_time('mysql'),
        'tutorial_shown' => false
      ));
    }
  }

  /**
   * Set tutorial status
   * 
   * @param array $status Tutorial status data
   * @return bool Whether the option was updated
   */
  public static function set_tutorial_status($status)
  {
    return update_option(self::TUTORIAL_STATUS_OPTION, $status);
  }

  /**
   * Get tutorial status
   * 
   * @return array Tutorial status data
   */
  public static function get_tutorial_status()
  {
    $status = get_option(self::TUTORIAL_STATUS_OPTION);

    if (!$status) {
      $status = array(
        'installation_date' => current_time('mysql'),
        'tutorial_shown' => false
      );
      self::set_tutorial_status($status);
    }

    return $status;
  }

  /**
   * Check if tutorial needs to be shown
   * 
   * @return bool Whether to show tutorial
   */
  public static function should_show_tutorial()
  {
    $status = self::get_tutorial_status();
    return !$status['tutorial_shown'];
  }

  /**
   * Mark tutorial as shown
   * 
   * @return bool Whether the option was updated
   */
  public static function mark_tutorial_shown()
  {
    $status = self::get_tutorial_status();
    $status['tutorial_shown'] = true;
    return self::set_tutorial_status($status);
  }
}
