<?php
/**
 * Operator Configuration
 *
 * Single source of truth for filter operators.
 * Used by FilterEvaluator, TriggerValidator, and AdminServiceProvider.
 *
 * @package Sequensy
 * @since 2.0.0
 */

declare(strict_types=1);

namespace Sequensy\Config;

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

/**
 * Class OperatorConfig
 *
 * Provides centralized filter operator configuration.
 */
class OperatorConfig {

	/**
	 * All available operators with labels.
	 *
	 * @var array<string, string>
	 */
	private const OPERATORS = array(
		'equals'       => 'Equals',
		'not_equals'   => 'Does not equal',
		'contains'     => 'Contains',
		'not_contains' => 'Does not contain',
		'greater_than' => 'Greater than',
		'less_than'    => 'Less than',
		'is_empty'     => 'Is empty',
		'is_not_empty' => 'Is not empty',
	);

	/**
	 * Operators grouped by field type.
	 *
	 * @var array<string, array<string>>
	 */
	private const OPERATORS_BY_TYPE = array(
		'string'   => array( 'equals', 'not_equals', 'contains', 'not_contains', 'is_empty', 'is_not_empty' ),
		'integer'  => array( 'equals', 'not_equals', 'greater_than', 'less_than', 'is_empty', 'is_not_empty' ),
		'boolean'  => array( 'equals', 'is_empty', 'is_not_empty' ),
		'datetime' => array( 'equals', 'not_equals', 'greater_than', 'less_than', 'is_empty', 'is_not_empty' ),
		'array'    => array( 'contains', 'not_contains', 'is_empty', 'is_not_empty' ),
	);

	/**
	 * Operators that require a value input.
	 *
	 * @var array<string>
	 */
	private const OPERATORS_REQUIRING_VALUE = array(
		'equals',
		'not_equals',
		'contains',
		'not_contains',
		'greater_than',
		'less_than',
	);

	/**
	 * Get all operator labels (translatable).
	 *
	 * @return array<string, string> Operator key => translated label.
	 */
	public static function get_operators(): array {
		return array(
			'equals'       => __( 'Equals', 'sequensy' ),
			'not_equals'   => __( 'Does not equal', 'sequensy' ),
			'contains'     => __( 'Contains', 'sequensy' ),
			'not_contains' => __( 'Does not contain', 'sequensy' ),
			'greater_than' => __( 'Greater than', 'sequensy' ),
			'less_than'    => __( 'Less than', 'sequensy' ),
			'is_empty'     => __( 'Is empty', 'sequensy' ),
			'is_not_empty' => __( 'Is not empty', 'sequensy' ),
		);
	}

	/**
	 * Get operators available for each field type.
	 *
	 * @return array<string, array<string>> Field type => operators.
	 */
	public static function get_operators_by_type(): array {
		return self::OPERATORS_BY_TYPE;
	}

	/**
	 * Get operators that require a value input.
	 *
	 * @return array<string> Operators requiring value.
	 */
	public static function get_operators_requiring_value(): array {
		return self::OPERATORS_REQUIRING_VALUE;
	}

	/**
	 * Get valid operators for a specific field type.
	 *
	 * @param string $field_type Field type (string, integer, boolean, datetime, array).
	 * @return array<string> Array of valid operator names.
	 */
	public static function get_operators_for_type( string $field_type ): array {
		return self::OPERATORS_BY_TYPE[ $field_type ] ?? self::OPERATORS_BY_TYPE['string'];
	}
}
