# Copyright (c) 2016 Luke San Antonio Bialecki
# All rights reserved.

from sqlalchemy.sql import and_

from .models import Pass


def query_user_passes(session, user_id, verified=None):
    if verified == True:
        # Only verified passes
        return session.query(Pass).filter(
            and_(Pass.owner_id == user_id, Pass.assigned_time != None)
        ).all()
    elif verified == False:
        # Only non-verified passes
        return session.query(Pass).filter(
            and_(Pass.owner_id == user_id, Pass.assigned_time == None)
        ).all()
    else:
        # All passes
        return session.query(Pass).filter(Pass.owner_id == user_id).all()


def query_org_passes(session, org_id, verified=None):
    if verified == True:
        # Only verified passes
        return session.query(Pass).filter(
            and_(Pass.org_id == org_id, Pass.assigned_time != None)
        ).all()
    elif verified == False:
        # Only non-verified passes
        return session.query(Pass).filter(
            and_(Pass.org_id == org_id, Pass.assigned_time == None)
        ).all()
    else:
        # All passes
        return session.query(Pass).filter(Pass.org_id == org_id).all()

@@ -191,34 +191,26 @@
  if verified
- == True
 :%0A
+
         # On
@@ -363,32 +363,36 @@
 ()%0A    elif 
+not 
 verified
  == False:%0A 
@@ -375,33 +375,24 @@
 not verified
- == False
 :%0A        # 
@@ -726,16 +726,8 @@
 fied
- == True
 :%0A  
@@ -891,24 +891,28 @@
    elif 
+not 
 verified
  == Fals
@@ -907,17 +907,8 @@
 fied
- == False
 :%0A  

Simplify boolean expressions in pass_util