<?php

namespace Planaday\Utility\Debug\Checking;

use Planaday\Utility\Debug\Checking\Checks\ApiKeyCheck;
use Planaday\Utility\Debug\Checking\Checks\ApiUrlCheck;
use Planaday\Utility\Debug\Checking\Checks\BookingFormOnDetailsPageCheck;
use Planaday\Utility\Debug\Checking\Checks\DatabaseValidCheck;
use Planaday\Utility\Debug\Checking\Checks\DetailsPageCheck;
use Planaday\Utility\Debug\Checking\Checks\PaymentActiveCheck;
use Planaday\Utility\Debug\Checking\Checks\ThanksCheck;
use Planaday\Utility\Debug\Log\Logging;
use Planaday\Utility\DependencyInjection\Container;
use Planaday\Utility\DependencyInjection\InjectionImpossibleException;

class ConnectorChecker {
	use Logging;

	public function __construct(
		protected Container $registry
	) {}

	public function getCheck(string $type): ?Check {
		try {
			switch ($type) {
				case ChecksEnum::IS_API_KEY_SET:
					return $this->registry->getInstance(ApiKeyCheck::class);
				case ChecksEnum::IS_API_URL_SET:
					return $this->registry->getInstance(ApiUrlCheck::class);
				case ChecksEnum::IS_DATABASE_VALID:
					return $this->registry->getInstance(DatabaseValidCheck::class);
				case ChecksEnum::IS_PAYMENT_ACTIVE:
					return $this->registry->getInstance(PaymentActiveCheck::class);
				case ChecksEnum::IS_DETAILS_PAGE_SET:
					return $this->registry->getInstance(DetailsPageCheck::class);
				case ChecksEnum::IS_BOOKING_FORM_ON_DETAILS_PAGE:
					return $this->registry->getInstance(BookingFormOnDetailsPageCheck::class);
				case ChecksEnum::IS_THANKS_SET:
					return $this->registry->getInstance(ThanksCheck::class);

				default:
					$this->logWarning('Check type not found: ' . $type);
					return null;
			}
		} catch (InjectionImpossibleException $e){
			$this->logError('Failed to make check: ' . $e->getMessage());
			return null;
		}
	}
}