# Path: sampletester/parser.py
# SCHEMA_TYPE_KEY = 'type'
# SCHEMA_TYPE_ABSENT = '(no type)' # for indexing docs with no SCHEMA_TYPE_KEY
# SCHEMA_TYPE_SEPARATOR = '/'
# SCHEMA_VERSION_KEY = 'schema_version'
# class SchemaDescriptor:
# class IndexedDocs(object):
# class YamlDocSyntaxError(Exception):
#   def __post_init__(self) -> str:
#   def has_version(self) -> bool:
#   def __init__(self,
#                strict: bool = False,
#                resolver: Callable[[Document], str] = None):
#   def contains(self, *type_names: str) -> bool:
#   def from_files(self, *paths: str):
#   def from_strings(self, *sources: Tuple[str, str]):
#   def add(self, content:str, file_name: str):
#   def add_documents(self, *documents: Document):
#   def of_type(self, type_name: str) -> List[Document]:
#   def resolve_uncategorized(self):
# def only_files_in(paths: Iterable[str]) -> Set[str]:
# 
# Path: sampletester/parser.py
# SCHEMA_TYPE_ABSENT = '(no type)' # for indexing docs with no SCHEMA_TYPE_KEY
# 
# Path: sampletester/sample_manifest.py
# SCHEMA = parser.SchemaDescriptor('manifest')
# 
# Path: sampletester/testplan.py
# SCHEMA = parser.SchemaDescriptor('test','samples', 1)


import glob
import itertools
import logging
import os
from functools import reduce
from typing import Set
from sampletester import parser
from sampletester.parser import SCHEMA_TYPE_ABSENT as UNKNOWN_TYPE
from sampletester.sample_manifest import SCHEMA as MANIFEST_SCHEMA
from sampletester.testplan import SCHEMA as TESTPLAN_SCHEMA
  explicit_paths = get_globbed(*file_patterns)
  explicit_directories = {path for path in explicit_paths
                          if os.path.isdir(path)}
  files_in_directories = get_globbed(*{f'{path}/**/*.yaml'
                                       for path in explicit_directories})
  explicit_paths |= files_in_directories

  indexed_explicit = create_indexed_docs(*explicit_paths)
  has_manifests = indexed_explicit.contains(MANIFEST_SCHEMA.primary_type)
  has_testplans = indexed_explicit.contains(TESTPLAN_SCHEMA.primary_type)

  if (has_manifests and has_testplans):
    # We have successfully found needed inputs already.
    return log_files(indexed_explicit)

  if files_in_directories:
    # Because directories were specified, we use this as a signal to *not*
    # recurse into the cwd. The caller of this method is responsible for
    # reporting that one or both of the needed file types is missing.
    return log_files(indexed_explicit)

  implicit_files = get_globbed('**/*.yaml')
  indexed_implicit = create_indexed_docs(*implicit_files)
  if not has_testplans:
    indexed_explicit.add_documents(*indexed_implicit.of_type(TESTPLAN_SCHEMA.primary_type))
  if not has_manifests:
    indexed_explicit.add_documents(*indexed_implicit.of_type(MANIFEST_SCHEMA.primary_type))

  return log_files(indexed_explicit)


# Path: sampletester/parser.py
# SCHEMA_TYPE_KEY = 'type'
# SCHEMA_TYPE_ABSENT = '(no type)' # for indexing docs with no SCHEMA_TYPE_KEY
# SCHEMA_TYPE_SEPARATOR = '/'
# SCHEMA_VERSION_KEY = 'schema_version'
# class SchemaDescriptor:
# class IndexedDocs(object):
# class YamlDocSyntaxError(Exception):
#   def __post_init__(self) -> str:
#   def has_version(self) -> bool:
#   def __init__(self,
#                strict: bool = False,
#                resolver: Callable[[Document], str] = None):
#   def contains(self, *type_names: str) -> bool:
#   def from_files(self, *paths: str):
#   def from_strings(self, *sources: Tuple[str, str]):
#   def add(self, content:str, file_name: str):
#   def add_documents(self, *documents: Document):
#   def of_type(self, type_name: str) -> List[Document]:
#   def resolve_uncategorized(self):
# def only_files_in(paths: Iterable[str]) -> Set[str]:
# 
# Path: sampletester/parser.py
# SCHEMA_TYPE_ABSENT = '(no type)' # for indexing docs with no SCHEMA_TYPE_KEY
# 
# Path: sampletester/sample_manifest.py
# SCHEMA = parser.SchemaDescriptor('manifest')
# 
# Path: sampletester/testplan.py
# SCHEMA = parser.SchemaDescriptor('test','samples', 1)


# Path: sampletester/inputs.py
import glob
import itertools
import logging
import os
from functools import reduce
from typing import Set
from sampletester import parser
from sampletester.parser import SCHEMA_TYPE_ABSENT as UNKNOWN_TYPE
from sampletester.sample_manifest import SCHEMA as MANIFEST_SCHEMA
from sampletester.testplan import SCHEMA as TESTPLAN_SCHEMA

  explicit_paths = get_globbed(*file_patterns)
  explicit_directories = {path for path in explicit_paths
                          if os.path.isdir(path)}
  files_in_directories = get_globbed(*{f'{path}/**/*.yaml'
                                       for path in explicit_directories})
  explicit_paths |= files_in_directories

  indexed_explicit = create_indexed_docs(*explicit_paths)
  has_manifests = indexed_explicit.contains(MANIFEST_SCHEMA.primary_type)
  has_testplans = indexed_explicit.contains(TESTPLAN_SCHEMA.primary_type)

  if (has_manifests and has_testplans):
    # We have successfully found needed inputs already.
    return log_files(indexed_explicit)

  if files_in_directories:
    # Because directories were specified, we use this as a signal to *not*
    # recurse into the cwd. The caller of this method is responsible for
    # reporting that one or both of the needed file types is missing.
    return log_files(indexed_explicit)

  implicit_files = get_globbed('**/*.yaml')
  indexed_implicit = create_indexed_docs(*implicit_files)
  if not has_testplans:
    indexed_explicit.add_documents(*indexed_implicit.of_type(TESTPLAN_SCHEMA.primary_type))
  if not has_manifests:
    indexed_explicit.add_documents(*indexed_implicit.of_type(MANIFEST_SCHEMA.primary_type))

  return log_files(indexed_explicit)


def create_indexed_docs(*all_paths: Set[str]) -> parser.IndexedDocs: