# Path: spanner_orm/error.py
# class SpannerError(Exception):
# class ValidationError(Exception):
# 
# Path: spanner_orm/field.py
# class FieldType(abc.ABC):
# class Field(object):
# class Boolean(FieldType):
# class Integer(FieldType):
# class Float(FieldType):
# class String(FieldType):
# class StringArray(FieldType):
# class Timestamp(FieldType):
# class BytesBase64(FieldType):
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def __init__(self,
#                field_type: Type[FieldType],
#                nullable: bool = False,
#                primary_key: bool = False):
#   def ddl(self) -> str:
#   def field_type(self) -> Type[FieldType]:
#   def grpc_type(self) -> str:
#   def nullable(self) -> bool:
#   def primary_key(self) -> bool:
#   def validate(self, value) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value) -> None:
# ALL_TYPES = [
#     Boolean, Integer, Float, String, StringArray, Timestamp, BytesBase64
# ]
# 
# Path: spanner_orm/foreign_key_relationship.py
# class ForeignKeyRelationshipConstraint:
# class ForeignKeyRelationship(object):
#   def __init__(self, referenced_table_name: str, columns: Mapping[str, str]):
#   def constraint(self) -> ForeignKeyRelationshipConstraint:
#   def ddl(self) -> str:
#   def _parse_constraint(self) -> ForeignKeyRelationshipConstraint:
#   def single(self) -> bool:
# 
# Path: spanner_orm/index.py
# class Index(object):
#   PRIMARY_INDEX = 'PRIMARY_KEY'
#   def __init__(self,
#                columns: List[str],
#                parent: Optional[str] = None,
#                null_filtered: bool = False,
#                unique: bool = False,
#                storing_columns: Optional[List[str]] = None):
#   def primary(self) -> bool:
# 
# Path: spanner_orm/registry.py
# class RegistryComponent:
# class Registry(object):
#   def add(self, reference: Type[Any]) -> None:
#   def __init__(self):
#   def _name_from_class(self, klass: Type[Any]) -> str:
#   def register(self, to_register: Type[Any]) -> None:
#   def get(self, name: Union[Type[Any], str]) -> Type[Any]:
# def model_registry():
# 
# Path: spanner_orm/relationship.py
# class RelationshipConstraint:
# class Relationship(object):
#   def __init__(self,
#                destination_handle: Union[Type[Any], str],
#                constraints: Dict[str, str],
#                is_parent: bool = False,
#                single: bool = False):
#   def constraints(self) -> List[RelationshipConstraint]:
#   def destination(self) -> Type[Any]:
#   def single(self) -> bool:
#   def _parse_constraints(self) -> List[RelationshipConstraint]:


from typing import Any, Dict, Type, Optional
from spanner_orm import error
from spanner_orm import field
from spanner_orm import foreign_key_relationship
from spanner_orm import index
from spanner_orm import registry
from spanner_orm import relationship
               model_class: Optional[Type[Any]] = None):
    self.columns = []
    self.fields = dict(fields or {})
    self._finalized = False
    self.indexes = dict(indexes or {})
    self.interleaved = interleaved
    self.model_class = model_class
    self.primary_keys = []
    self.relations = dict(relations or {})
    self.foreign_key_relations = dict(foreign_key_relations or {})
    self.table = table or ''

  def finalize(self) -> None:
    """Finish generating metadata state.

    Some metadata depends on having all configuration data set before it can
    be calculated--the primary index, for example, needs all fields to be added
    before it can be calculated. This method is called to indicate that all
    relevant state has been added and the calculation of the final data should
    now happen.
    """
    if self._finalized:
      raise error.SpannerError('Metadata was already finalized')
    sorted_fields = list(sorted(self.fields.values(), key=lambda f: f.position))

    if index.Index.PRIMARY_INDEX not in self.indexes:
      primary_keys = [f.name for f in sorted_fields if f.primary_key()]
      primary_index = index.Index(primary_keys)
      primary_index.name = index.Index.PRIMARY_INDEX
      self.indexes[index.Index.PRIMARY_INDEX] = primary_index

# Path: spanner_orm/error.py
# class SpannerError(Exception):
# class ValidationError(Exception):
# 
# Path: spanner_orm/field.py
# class FieldType(abc.ABC):
# class Field(object):
# class Boolean(FieldType):
# class Integer(FieldType):
# class Float(FieldType):
# class String(FieldType):
# class StringArray(FieldType):
# class Timestamp(FieldType):
# class BytesBase64(FieldType):
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def __init__(self,
#                field_type: Type[FieldType],
#                nullable: bool = False,
#                primary_key: bool = False):
#   def ddl(self) -> str:
#   def field_type(self) -> Type[FieldType]:
#   def grpc_type(self) -> str:
#   def nullable(self) -> bool:
#   def primary_key(self) -> bool:
#   def validate(self, value) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value: Any) -> None:
#   def ddl() -> str:
#   def grpc_type() -> type_pb2.Type:
#   def validate_type(value) -> None:
# ALL_TYPES = [
#     Boolean, Integer, Float, String, StringArray, Timestamp, BytesBase64
# ]
# 
# Path: spanner_orm/foreign_key_relationship.py
# class ForeignKeyRelationshipConstraint:
# class ForeignKeyRelationship(object):
#   def __init__(self, referenced_table_name: str, columns: Mapping[str, str]):
#   def constraint(self) -> ForeignKeyRelationshipConstraint:
#   def ddl(self) -> str:
#   def _parse_constraint(self) -> ForeignKeyRelationshipConstraint:
#   def single(self) -> bool:
# 
# Path: spanner_orm/index.py
# class Index(object):
#   PRIMARY_INDEX = 'PRIMARY_KEY'
#   def __init__(self,
#                columns: List[str],
#                parent: Optional[str] = None,
#                null_filtered: bool = False,
#                unique: bool = False,
#                storing_columns: Optional[List[str]] = None):
#   def primary(self) -> bool:
# 
# Path: spanner_orm/registry.py
# class RegistryComponent:
# class Registry(object):
#   def add(self, reference: Type[Any]) -> None:
#   def __init__(self):
#   def _name_from_class(self, klass: Type[Any]) -> str:
#   def register(self, to_register: Type[Any]) -> None:
#   def get(self, name: Union[Type[Any], str]) -> Type[Any]:
# def model_registry():
# 
# Path: spanner_orm/relationship.py
# class RelationshipConstraint:
# class Relationship(object):
#   def __init__(self,
#                destination_handle: Union[Type[Any], str],
#                constraints: Dict[str, str],
#                is_parent: bool = False,
#                single: bool = False):
#   def constraints(self) -> List[RelationshipConstraint]:
#   def destination(self) -> Type[Any]:
#   def single(self) -> bool:
#   def _parse_constraints(self) -> List[RelationshipConstraint]:


# Path: spanner_orm/metadata.py
from typing import Any, Dict, Type, Optional
from spanner_orm import error
from spanner_orm import field
from spanner_orm import foreign_key_relationship
from spanner_orm import index
from spanner_orm import registry
from spanner_orm import relationship

               model_class: Optional[Type[Any]] = None):
    self.columns = []
    self.fields = dict(fields or {})
    self._finalized = False
    self.indexes = dict(indexes or {})
    self.interleaved = interleaved
    self.model_class = model_class
    self.primary_keys = []
    self.relations = dict(relations or {})
    self.foreign_key_relations = dict(foreign_key_relations or {})
    self.table = table or ''

  def finalize(self) -> None:
    """Finish generating metadata state.

    Some metadata depends on having all configuration data set before it can
    be calculated--the primary index, for example, needs all fields to be added
    before it can be calculated. This method is called to indicate that all
    relevant state has been added and the calculation of the final data should
    now happen.
    """
    if self._finalized:
      raise error.SpannerError('Metadata was already finalized')
    sorted_fields = list(sorted(self.fields.values(), key=lambda f: f.position))

    if index.Index.PRIMARY_INDEX not in self.indexes:
      primary_keys = [f.name for f in sorted_fields if f.primary_key()]
      primary_index = index.Index(primary_keys)
      primary_index.name = index.Index.PRIMARY_INDEX
      self.indexes[index.Index.PRIMARY_INDEX] = primary_index

    self.primary_keys = self.indexes[index.Index.PRIMARY_INDEX].columns