# Path: conditional/models/models.py
# class InHousingQueue(db.Model):
#     __tablename__ = 'in_housing_queue'
#     uid = Column(String(32), primary_key=True)
# 
# Path: conditional/models/models.py
# class OnFloorStatusAssigned(db.Model):
#     __tablename__ = 'onfloor_datetime'
#     uid = Column(String(32), primary_key=True)
#     onfloor_granted = Column(DateTime, primary_key=True)
# 
#     def __init__(self, uid, time_granted):
#         self.uid = uid
#         self.onfloor_granted = time_granted
# 
# Path: conditional/util/ldap.py
# @service_cache(maxsize=1024)
# def ldap_get_current_students():
#     return _ldap_get_group_members("current_student")
# 
# Path: conditional/util/ldap.py
# @service_cache(maxsize=128)
# def ldap_is_onfloor(account):
#     return _ldap_is_member_of_group(account, 'onfloor')


from datetime import datetime
from conditional.models.models import InHousingQueue
from conditional.models.models import OnFloorStatusAssigned
from conditional.util.ldap import ldap_get_current_students
from conditional.util.ldap import ldap_is_onfloor



def get_housing_queue(is_eval_director=False):

    # Generate a dictionary of dictionaries where the UID is the key
    # and {'time': <datetime obj>} is the value. We are doing a left
    # outer join on the two tables to get a single result that has
    # both the member's UID and their on-floor datetime.
    in_queue = {entry.uid: {'time': entry.onfloor_granted} for entry
    in InHousingQueue.query.outerjoin(OnFloorStatusAssigned,
    OnFloorStatusAssigned.uid == InHousingQueue.uid)\

# Path: conditional/models/models.py
# class InHousingQueue(db.Model):
#     __tablename__ = 'in_housing_queue'
#     uid = Column(String(32), primary_key=True)
# 
# Path: conditional/models/models.py
# class OnFloorStatusAssigned(db.Model):
#     __tablename__ = 'onfloor_datetime'
#     uid = Column(String(32), primary_key=True)
#     onfloor_granted = Column(DateTime, primary_key=True)
# 
#     def __init__(self, uid, time_granted):
#         self.uid = uid
#         self.onfloor_granted = time_granted
# 
# Path: conditional/util/ldap.py
# @service_cache(maxsize=1024)
# def ldap_get_current_students():
#     return _ldap_get_group_members("current_student")
# 
# Path: conditional/util/ldap.py
# @service_cache(maxsize=128)
# def ldap_is_onfloor(account):
#     return _ldap_is_member_of_group(account, 'onfloor')


# Path: conditional/util/housing.py
from datetime import datetime
from conditional.models.models import InHousingQueue
from conditional.models.models import OnFloorStatusAssigned
from conditional.util.ldap import ldap_get_current_students
from conditional.util.ldap import ldap_is_onfloor




def get_housing_queue(is_eval_director=False):

    # Generate a dictionary of dictionaries where the UID is the key
    # and {'time': <datetime obj>} is the value. We are doing a left
    # outer join on the two tables to get a single result that has
    # both the member's UID and their on-floor datetime.
    in_queue = {entry.uid: {'time': entry.onfloor_granted} for entry
    in InHousingQueue.query.outerjoin(OnFloorStatusAssigned,
    OnFloorStatusAssigned.uid == InHousingQueue.uid)\

    .with_entities(InHousingQueue.uid, OnFloorStatusAssigned.onfloor_granted)\