<?php
/**
 * Official adapter roadmap catalog.
 *
 * @package ScheduledChanges
 */

namespace ScheduledChanges\Adapter;

use ScheduledChanges\Extension\PublicHooks;

/**
 * Lists prioritized adapter targets without claiming untested coverage.
 */
final class OfficialAdapterCatalog {
	/**
	 * Returns prioritized adapter definitions.
	 *
	 * @return OfficialAdapterDefinition[]
	 */
	public function definitions(): array {
		$definitions = array(
			new OfficialAdapterDefinition(
				'woocommerce-core',
				'WooCommerce',
				5,
				'woocommerce-core',
				array(
					$this->signal( 'class', 'WooCommerce', 'WooCommerce class' ),
					$this->signal( 'function', 'WC', 'WooCommerce API' ),
				),
				null,
				'Native WooCommerce product scheduling is supplied by the certified WooCommerce module.'
			),
			new OfficialAdapterDefinition(
				'advanced-custom-fields',
				'Advanced Custom Fields',
				10,
				'advanced-custom-fields',
				array(
					$this->signal( 'class', 'ACF', 'ACF class' ),
					$this->signal( 'function', 'acf_get_field_groups', 'ACF field-group API' ),
				),
				null,
				'Planned explicit adapter for field groups, values, clone suppression, and redaction.'
			),
			new OfficialAdapterDefinition(
				'woocommerce-product-modules',
				'WooCommerce Product Add-Ons',
				20,
				'woocommerce-product-modules',
				array(
					$this->signal( 'class', 'WC_Product_Addons', 'Product Add-Ons class' ),
					$this->signal( 'function', 'get_product_modules', 'Product Add-Ons API' ),
				),
				null,
				'Planned explicit adapter for module groups, pricing rules, validation, and rollback.'
			),
			new OfficialAdapterDefinition(
				'variation-swatches',
				'Variation swatch plugins',
				30,
				'variation-swatches',
				array(
					$this->signal( 'class', 'Woo_Variation_Swatches', 'Variation Swatches class' ),
					$this->signal( 'function', 'wvs_get_wc_attribute_taxonomies', 'Variation Swatches API' ),
				),
				null,
				'Planned adapter family; exact plugin support must be certified one plugin at a time.'
			),
			new OfficialAdapterDefinition(
				'woocommerce-subscriptions',
				'WooCommerce Subscriptions',
				40,
				'woocommerce-subscriptions',
				array(
					$this->signal( 'class', 'WC_Subscriptions', 'Subscriptions class' ),
					$this->signal( 'function', 'wcs_get_subscriptions', 'Subscriptions API' ),
				),
				null,
				'Planned explicit adapter for subscription product state and renewal side-effect policy.'
			),
			new OfficialAdapterDefinition(
				'woocommerce-product-bundles',
				'WooCommerce Product Bundles',
				50,
				'woocommerce-product-bundles',
				array(
					$this->signal( 'class', 'WC_Bundles', 'Product Bundles class' ),
					$this->signal( 'class', 'WC_Product_Bundle', 'Bundle product class' ),
				),
				null,
				'Planned explicit adapter for bundled items, quantities, pricing, and stock behavior.'
			),
			new OfficialAdapterDefinition(
				'woocommerce-composite-products',
				'WooCommerce Composite Products',
				60,
				'woocommerce-composite-products',
				array(
					$this->signal( 'class', 'WC_Composite_Products', 'Composite Products class' ),
					$this->signal( 'class', 'WC_Product_Composite', 'Composite product class' ),
				),
				null,
				'Planned explicit adapter for components, scenarios, pricing, and dependency validation.'
			),
			new OfficialAdapterDefinition(
				'woocommerce-bookings',
				'WooCommerce Bookings',
				70,
				'woocommerce-bookings',
				array(
					$this->signal( 'class', 'WC_Bookings', 'Bookings class' ),
					$this->signal( 'class', 'WC_Product_Booking', 'Booking product class' ),
				),
				null,
				'Planned explicit adapter for availability, resources, costs, and external booking side effects.'
			),
			new OfficialAdapterDefinition(
				'woocommerce-deposits',
				'WooCommerce Deposits',
				80,
				'woocommerce-deposits',
				array(
					$this->signal( 'class', 'WC_Deposits', 'Deposits class' ),
					$this->signal( 'class', 'WC_Deposits_Product_Manager', 'Deposits product manager' ),
				),
				null,
				'Planned explicit adapter for deposit schedules, payment plans, and validation.'
			),
			new OfficialAdapterDefinition(
				'woocommerce-brands',
				'WooCommerce Brands',
				90,
				'woocommerce-brands',
				array(
					$this->signal( 'taxonomy', 'product_brand', 'product_brand taxonomy' ),
					$this->signal( 'class', 'WC_Brands', 'Brands class' ),
				),
				'product-taxonomies',
				'Public product_brand taxonomy assignments are covered by the taxonomy discovery provider.'
			),
			new OfficialAdapterDefinition(
				'wholesale-pricing',
				'Wholesale pricing plugins',
				100,
				'wholesale-pricing',
				array(
					$this->signal( 'class', 'WWP_Wholesale_Prices', 'WooCommerce Wholesale Prices class' ),
					$this->signal( 'class', 'WooCommerceWholeSalePrices', 'Wholesale Prices class' ),
				),
				null,
				'Planned adapter family; source-of-truth and role pricing behavior must be certified per plugin.'
			),
			new OfficialAdapterDefinition(
				'multilingual',
				'Multilingual plugins',
				110,
				'multilingual',
				array(
					$this->signal( 'class', 'SitePress', 'WPML class' ),
					$this->signal( 'function', 'pll_current_language', 'Polylang API' ),
				),
				null,
				'Planned adapter family for translated product relationships and language-specific values.'
			),
			new OfficialAdapterDefinition(
				'multi-currency',
				'Multi-currency plugins',
				120,
				'multi-currency',
				array(
					$this->signal( 'class', 'WOOMULTI_CURRENCY', 'WooCommerce Multi Currency class' ),
					$this->signal( 'class', 'WC_Aelia_CurrencySwitcher', 'Aelia Currency Switcher class' ),
				),
				null,
				'Planned adapter family for currency-specific prices and exchange-rate source-of-truth policy.'
			),
			new OfficialAdapterDefinition(
				'seo-product-metadata',
				'SEO plugins for product metadata',
				130,
				'seo-product-metadata',
				array(
					$this->signal( 'class', 'WPSEO_Options', 'Yoast SEO class' ),
					$this->signal( 'class', 'RankMath', 'Rank Math class' ),
				),
				null,
				'Planned adapter family for SEO metadata ownership, snippets, schemas, and redaction.'
			),
			new OfficialAdapterDefinition(
				'cost-of-goods',
				'Cost-of-goods extensions',
				140,
				'cost-of-goods',
				array(
					$this->signal( 'class', 'WC_COG', 'Cost of Goods class' ),
					$this->signal( 'class', 'WC_Cost_Of_Goods', 'Cost of Goods class' ),
				),
				null,
				'Planned adapter family. Cost data is sensitive and must remain redacted by default.'
			),
			new OfficialAdapterDefinition(
				'external-inventory',
				'External inventory integrations',
				150,
				'external-inventory',
				array(
					$this->signal( 'constant', 'SCHEDULED_CHANGES_EXTERNAL_INVENTORY_ADAPTER', 'Scheduled Changes external inventory marker' ),
				),
				null,
				'Planned adapter family requiring source-of-truth, health-check, retry, and reconciliation policy.'
			),
		);

		$definitions = array_values(
			array_filter(
				PublicHooks::adapterDefinitions( $definitions ),
				static fn ( $definition ): bool => $definition instanceof OfficialAdapterDefinition
			)
		);

		usort(
			$definitions,
			static fn ( OfficialAdapterDefinition $left, OfficialAdapterDefinition $right ): int => $left->priority() <=> $right->priority()
		);

		return $definitions;
	}

	/**
	 * Creates a detection signal.
	 *
	 * @param string $type Signal type.
	 * @param string $value Signal value.
	 * @param string $label Human-readable signal label.
	 * @return array{type:string,value:string,label:string}
	 */
	private function signal( string $type, string $value, string $label ): array {
		return array(
			'type'  => $type,
			'value' => $value,
			'label' => $label,
		);
	}
}
