<?php
/**
 * Site operating profile shared by founder, heartbeat, and report runtimes.
 *
 * @package Niwa_AI
 */

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

trait Niwa_AI_Chat_Site_Profile {

	private function get_site_operating_profile() {
		$woocommerce_active = class_exists( 'WooCommerce' ) && function_exists( 'wc_get_products' );
		$ui_settings        = function_exists( 'get_option' )
			? get_option( Niwa_AI_Constants::OPT_UI_SETTINGS, array() )
			: array();
		$action_mode        = is_array( $ui_settings ) && isset( $ui_settings['product_card_action_mode'] )
			? sanitize_key( (string) $ui_settings['product_card_action_mode'] )
			: 'store';
		$commerce_mode      = ! $woocommerce_active ? 'none' : ( 'catalog' === $action_mode ? 'catalog' : 'store' );

		return array(
			'commerce_mode'         => $commerce_mode,
			'woocommerce_active'    => $woocommerce_active,
			'catalog_available'     => $woocommerce_active,
			'transactions_available' => 'store' === $commerce_mode,
		);
	}

	private function build_site_operating_profile_context() {
		$profile = $this->get_site_operating_profile();

		return implode(
			"\n",
			array(
				'Commerce mode: ' . (string) $profile['commerce_mode'],
				'WooCommerce active: ' . ( $profile['woocommerce_active'] ? 'yes' : 'no' ),
				'Product catalog available: ' . ( $profile['catalog_available'] ? 'yes' : 'no' ),
				'Transactional commerce available: ' . ( $profile['transactions_available'] ? 'yes' : 'no' ),
			)
		);
	}
}
