<?php

namespace Dokan\TryAura\DependencyManagement\Providers;

if ( ! defined( 'ABSPATH' ) ) {
	exit; // Exit if accessed directly.
}

use Dokan\TryAura\DependencyManagement\BaseServiceProvider;
use Dokan\TryAura\TryAura;
use Dokan\TryAura\WooCommerce\Frontend\TryOn;
use Dokan\TryAura\WooCommerce\WooCommerce;
use Dokan\TryAura\WooCommerce\Admin\ProductGalleryVideo as AdminProductVideo;
use Dokan\TryAura\WooCommerce\Frontend\ProductVideoGallery as FrontendProductVideo;

/**
 * WooCommerceServiceProvider Class
 *
 * @since 1.0.0
 */
class WooCommerceServiceProvider extends BaseServiceProvider {

	/**
	 * The services provided by this provider.
	 *
	 * @since 1.0.0
	 *
	 * @var array
	 */
	protected $services = [
		'woocommerce'           => WooCommerce::class,
		'admin_product_video' => AdminProductVideo::class,
		'frontend_product_video' => FrontendProductVideo::class,
		'try_on'                => TryOn::class,
	];

	/**
	 * {@inheritDoc}
	 *
	 * @since 1.0.0
	 */
	public function provides( string $alias ): bool {
		return class_exists( 'WooCommerce' )&& parent::provides( $alias );
	}

	/**
	 * Register the classes.
	 *
	 * @since 1.0.0
	 */
	public function register(): void {
		$filtered_services = apply_filters( 'tryaura_woocommerce_container_services', $this->services );
		foreach ( $filtered_services as $key => $class_name ) {
			$this->getContainer()->addShared( $key, $class_name );
		}
	}
}
