<?php
/**
 * Base muxer engine for The Studio Player.
 *
 * @package The Studio Player
 */

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

if ( ! class_exists( 'THESPL_Muxer_Engine' ) ) {
	/**
	 * Base muxer engine.
	 */
	class THESPL_Muxer_Engine {

		/**
		 * Get the total number of slot cards rendered in the UI.
		 *
		 * @return int
		 */
		public function get_rendered_slot_count() {
			return 4;
		}

		/**
		 * Get the number of operational slots for the current engine.
		 *
		 * @return int
		 */
		public function get_operational_slot_count() {
			return 2;
		}

		/**
		 * Check whether a slot is operational in the current engine.
		 *
		 * @param int $slot_index Slot index.
		 * @return bool
		 */
		public function is_slot_operational( $slot_index ) {
			$slot_index = (int) $slot_index;

			return $slot_index >= 0 && $slot_index < $this->get_operational_slot_count();
		}

		/**
		 * Get the supported sample rates for the engine.
		 *
		 * @return array
		 */
		public function get_supported_sample_rates() {
			return array( 44100 );
		}

		/**
		 * Get the supported bit depths for the engine.
		 *
		 * @return array
		 */
		public function get_supported_bit_depths() {
			return array( 16 );
		}

		/**
		 * Check whether the engine supports high-resolution input.
		 *
		 * @return bool
		 */
		public function supports_high_resolution_input() {
			return false;
		}

		/**
		 * Check whether the engine supports waveform generation.
		 *
		 * @return bool
		 */
		public function supports_waveform_generation() {
			return false;
		}

		/**
		 * Get the maximum output channels for the engine.
		 *
		 * @return int
		 */
		public function get_max_output_channels() {
			return $this->get_operational_slot_count() * 2;
		}

		/**
		 * Get a localized engine config payload for JavaScript.
		 *
		 * @return array
		 */
		public function get_js_config() {
			return array(
				'max_slots'                    => $this->get_operational_slot_count(),
				'rendered_slots'               => $this->get_rendered_slot_count(),
				'max_channels'                 => $this->get_max_output_channels(),
				'allowed_sample_rates'         => $this->get_supported_sample_rates(),
				'allowed_bit_depths'           => $this->get_supported_bit_depths(),
				'supports_waveform_generation' => $this->supports_waveform_generation(),
			);
		}
	}
}
