<?php

namespace Fifa\ConnectId\Sdk\Util\XsdSchemaValidator;

use DomainException;

class XsdSchemasDirectoryResolver
{
    /**
     * @var string
     */
    private static $directoryContainingXsdFiles;

    /**
     * XsdSchemasDirectoryResolver static constructor.
     */
    public static function __constructStatic()
    {
        self::$directoryContainingXsdFiles = dirname(__FILE__) . DIRECTORY_SEPARATOR . 'XsdResources';
        self::validateScenariosXsdFileExists(self::$directoryContainingXsdFiles);
    }

    /**
     * Returns xsd schema files location
     *
     * @return string
     */
    public static function getDirectory(): string
    {
        return self::$directoryContainingXsdFiles;
    }

    private static function validateScenariosXsdFileExists($directoryContainingXsdFiles)
    {
        $scenariosFileName = "scenarios.xsd";
        if (!file_exists($directoryContainingXsdFiles . DIRECTORY_SEPARATOR . $scenariosFileName))
        {
            throw new DomainException("$scenariosFileName file could not be found in the following location: $directoryContainingXsdFiles");
        }
    }
}

XsdSchemasDirectoryResolver::__constructStatic();