"""
Query
=====

Interface between backend/database and Views. Aims to abstract database lookups for the frontend as well as possible.

Contents
--------
Classes
-------

Functions
---------

Public variables
----------------
"""
import django.db.models
import pt_map.models
from pt_map.class_names import class_names

class GTFSQuery:
    """
    Base datatype conveniently storing data requiring queries involving multiple tables as if they were a GTFS Feed as described by the GTFS specification.
    Main abstraction element between data handling and frontend.
    
    Attributes
    ----------

    Methods
    -------
    """
    def __init__(self, queries: dict[str, django.db.models.query.QuerySet]):
        """
        Parameters
        ----------
        queries : dict[str, django.db.models.query.QuerySet]
            dict containing 
            keys: str specifying the file of the GTFS reference they represent either as the file name omitting the extension or as Model name in CamelCase or as model name all lower case.
            values: QuerySets of the specified models

        Raises
        ------
        TypeError
            If queries is not present or of bad type
        ValueError
            If queries contains a Key not specified as a file in the GTFS reference
        """
        if not queries or not isinstance(queries, dict):
            raise TypeError("Missing dict of QuerySets")
        for key,value in queries.items():
            for names in class_names:
                if names.get(key):
                    cls = names[key]
            if not cls:
                raise ValueError("Bad GTFS file name")

