<?php
/**
 * PositionType class.
 *
 * Defines widget display positions for the PromoTimeWidget module
 * used on the WooCommerce single product page.
 *
 * @package Ilabs\Firevert\Modules\PromoTimeWidget\Services\Type
 */

declare( strict_types=1 );

namespace Ilabs\Firevert\Modules\PromoTimeWidget\Services\Type;

/**
 * Class PositionType
 *
 * Provides supported widget positions and utility methods.
 */
final class PositionType {

	/**
	 * Widget positioned after the add to cart button.
	 */
	public const AFTER_ADD_TO_CART_BUTTON = 'after_add_to_cart_button';

	/**
	 * Widget positioned before the add to cart form.
	 */
	public const BEFORE_ADD_TO_CART_FORM = 'before_add_to_cart_form';

	/**
	 * Widget positioned before the variations form.
	 */
	public const BEFORE_VARIATIONS_FORM = 'before_variations_form';

	/**
	 * Widget positioned before the add to cart button.
	 */
	public const BEFORE_ADD_TO_CART_BUTTON = 'before_add_to_cart_button';

	/**
	 * Widget positioned before the single variation.
	 */
	public const BEFORE_SINGLE_VARIATION = 'before_single_variation';

	/**
	 * Widget positioned before the quantity field.
	 */
	public const BEFORE_QUANTITY_FIELD = 'before_add_to_cart_quantity';

	/**
	 * Widget positioned after the quantity field.
	 */
	public const AFTER_QUANTITY_FIELD = 'after_add_to_cart_quantity';

	/**
	 * Widget positioned after the variations form.
	 */
	public const AFTER_VARIATIONS_FORM = 'after_variations_form';

	/**
	 * Widget positioned after the add to cart form.
	 */
	public const AFTER_ADD_TO_CART_FORM = 'after_add_to_cart_form';

	/**
	 * Widget positioned at the product meta start.
	 */
	public const PRODUCT_META_START = 'product_meta_start';

	/**
	 * Widget positioned at the product meta end.
	 */
	public const PRODUCT_META_END = 'product_meta_end';

	/**
	 * Widget positioned after the single product summary.
	 */
	public const AFTER_SINGLE_PRODUCT_SUMMARY = 'after_single_product_summary';

	/**
	 * Returns all available widget display positions.
	 *
	 * @return array<string, string> List of positions in key => label format.
	 */
	public static function get_all(): array {
		return array(
			self::AFTER_ADD_TO_CART_BUTTON     => __( 'After the "Add to cart" button', 'firevert' ),
			self::BEFORE_ADD_TO_CART_FORM      => __( 'Before the "Add to cart" form', 'firevert' ),
			self::BEFORE_VARIATIONS_FORM       => __( 'Before the variations form', 'firevert' ),
			self::BEFORE_ADD_TO_CART_BUTTON    => __( 'Before the "Add to cart" button', 'firevert' ),
			self::BEFORE_SINGLE_VARIATION      => __( 'Before single variation', 'firevert' ),
			self::BEFORE_QUANTITY_FIELD        => __( 'Before quantity field', 'firevert' ),
			self::AFTER_QUANTITY_FIELD         => __( 'After quantity field', 'firevert' ),
			self::AFTER_VARIATIONS_FORM        => __( 'After variations form', 'firevert' ),
			self::AFTER_ADD_TO_CART_FORM       => __( 'After the "Add to cart" form', 'firevert' ),
			self::PRODUCT_META_START           => __( 'Product meta start', 'firevert' ),
			self::PRODUCT_META_END             => __( 'Product meta end', 'firevert' ),
			self::AFTER_SINGLE_PRODUCT_SUMMARY => __( 'After single product summary', 'firevert' ),
		);
	}

	/**
	 * Checks if a given position value is valid.
	 *
	 * @param string $position The position identifier.
	 *
	 * @return bool True if the position exists, false otherwise.
	 */
	public static function exists( string $position ): bool {
		return array_key_exists( $position, self::get_all() );
	}

	/**
	 * Retrieves the label for a given position value.
	 *
	 * @param string $position The position identifier.
	 *
	 * @return string|null The label if found, or null.
	 */
	public static function get_label( string $position ): ?string {
		$all = self::get_all();

		return $all[ $position ] ?? null;
	}
}
