text: import json
  from dataclasses import dataclass, asdict
  from functools import cached_property
  from pathlib import Path
  from typing import Any, Dict, List, NamedTuple, Union
  
  #from jsonschema import Draft7Validator
  from jsonschema.exceptions import ValidationError
  from yaml import safe_load
  
  from pyinsights.exceptions import (
      ConfigInvalidSyntaxError,
      ConfigNotFoundError,
      ConfigVersionUnknownError,
      InvalidVersionError
  )
  from pyinsights.helper import (
      convert_to_epoch,
      convert_string_duration_to_datetime,
      DatetimeType
  )
  
  
  ConfigType = Dict[str, Any]
  SchemaType = Dict[str, Any]
  
  
  class ConfigFile(NamedTuple):
      filename: str
      content: ConfigType
  
      @classmethod
      def from_filename(cls, filename) -> 'ConfigFile':
          return cls(filename, load_yaml(filename))
  
      @property
      def version(self) -> str:
          try:
              return self.content['version']
          except KeyError:
              raise ConfigVersionUnknownError(
                  'Please Specify configuration version'
              )
  
      def convert_duration(self) -> Dict[str, int]:
          duration = self.content['duration']
  
          if isinstance(duration, str):
              duration = convert_string_duration_to_datetime(duration)
  
          duration_epoch = {
              key: convert_to_epoch(value)
              for key, value in duration.items()
          }
          return duration_epoch
  
      def get_query_params(self, dates, some_data) -> ConfigType:
  
          query =  self.content['query_string']
          
          if some_data:
              for k in some_data:
                  astr = "{{" +k + "}}"
                  value = some_data[k]
                  if astr in query:
                      query = query.replace(astr, value)
              #print (query)
              
          if dates[0]:
              self.content['duration'] = {
                  'start_time': str(dates[0]) + " 00:00:00",
                  'end_time': str(dates[1])  + " 00:00:00",
              }
          params = self.content.copy()
  
          del params['version']
          params['query_string'] = query
          
          new_duration = self.convert_duration()
          del params['duration']
          params.update(new_duration)
          return params
  
  
  def load_config(filepath: str) -> ConfigType:
      """Load configuration
  
      Arguments:
          filepath {str}
  
      Returns:
          {ConfigType} -- query parameters
      """
  
      config = ConfigFile.from_filename(filepath)
      validate(config.content, config.version)
      return config
  
  
  def load_yaml(filepath: str) -> ConfigType:
      """Load YAML configuration file
  
      Arguments:
          filepath {str}
  
      Raises:
          ConfigNotFoundError
  
      Returns:
          config {ConfigType}
      """
  
      try:
          with open(filepath) as fd:
              return safe_load(fd)
      except FileNotFoundError:
          raise ConfigNotFoundError('Could not find the configuration')
  
  
  def load_schema(version: str) -> SchemaType:
      """Load the schema json file
  
      Arguments:
          version {str}
  
      Raises:
          InvalidVersionError
  
      Returns:
          schema {SchemaType}
      """
  
      basepath = Path(__file__).parent.resolve()
      filename = f'version_{version}.json'
      schema_filpath = f'{basepath}/schema/{filename}'
  
      try:
          with open(schema_filpath) as fd:
              return json.load(fd)
      except FileNotFoundError:
          raise InvalidVersionError(f'The version {repr(version)} is invalid')
  
  
  def validate(config: ConfigType, version: str) -> bool:
      """Validate the configuration
  
      Arguments:
          config {ConfigType}
          version {str}
  
      Raises:
          ConfigInvalidSyntaxError
  
      Returns:
          bool
      """
  
      try:
          schema = load_schema(version)
  #        Draft7Validator(schema).validate(config)
      except ValidationError as err:
          raise ConfigInvalidSyntaxError(err)
      except Exception as err:
          raise err
      else:
          return True
  