# Path: pokedex/search.py
# def search(session, **criteria):
#     query = (
#         session.query(t.Pokemon)
#         .options(
#             joinedload(t.Pokemon.species)
#         )
#     )
# 
#     stat_query = (
#         session.query(t.PokemonStat.pokemon_id)
#         .join(t.PokemonStat.stat)
#     )
#     do_stat = False
# 
#     if criteria.get('name') is not None:
#         query = query.join(t.Pokemon.species)
#         query = query.join(t.PokemonSpecies.names_local)
#         query = query.filter(func.lower(t.PokemonSpecies.names_table.name) == criteria['name'].lower())
# 
#     for stat_ident in (u'attack', u'defense', u'special-attack', u'special-defense', u'speed', u'hp'):
#         criterion = criteria.get(stat_ident)
#         if criterion is None:
#             continue
# 
#         do_stat = True
#         stat_query = stat_query.filter(
#             (t.Stat.identifier == stat_ident)
#             & _parse_range(criterion)(t.PokemonStat.base_stat)
#         )
# 
#     if do_stat:
#         query = query.filter(t.Pokemon.id.in_(stat_query.subquery()))
# 
#     return query.all()


from pokedex.search import search
    from pokedex.main import get_session


def configure_parser(parser):
    parser.set_defaults(func=command_search)

    parser.add_argument('--name', default=None)

    parser.add_argument('--attack', '--atk', dest='attack', default=None)
    parser.add_argument('--defense', '--def', dest='defense', default=None)
    parser.add_argument('--special-attack', '--spatk', dest='special-attack', default=None)
    parser.add_argument('--special-defense', '--spdef', dest='special-defense', default=None)
    parser.add_argument('--speed', dest='speed', default=None)
    parser.add_argument('--hp', dest='hp', default=None)



# Path: pokedex/search.py
# def search(session, **criteria):
#     query = (
#         session.query(t.Pokemon)
#         .options(
#             joinedload(t.Pokemon.species)
#         )
#     )
# 
#     stat_query = (
#         session.query(t.PokemonStat.pokemon_id)
#         .join(t.PokemonStat.stat)
#     )
#     do_stat = False
# 
#     if criteria.get('name') is not None:
#         query = query.join(t.Pokemon.species)
#         query = query.join(t.PokemonSpecies.names_local)
#         query = query.filter(func.lower(t.PokemonSpecies.names_table.name) == criteria['name'].lower())
# 
#     for stat_ident in (u'attack', u'defense', u'special-attack', u'special-defense', u'speed', u'hp'):
#         criterion = criteria.get(stat_ident)
#         if criterion is None:
#             continue
# 
#         do_stat = True
#         stat_query = stat_query.filter(
#             (t.Stat.identifier == stat_ident)
#             & _parse_range(criterion)(t.PokemonStat.base_stat)
#         )
# 
#     if do_stat:
#         query = query.filter(t.Pokemon.id.in_(stat_query.subquery()))
# 
#     return query.all()


# Path: pokedex/cli/search.py
from pokedex.search import search
    from pokedex.main import get_session



def configure_parser(parser):
    parser.set_defaults(func=command_search)

    parser.add_argument('--name', default=None)

    parser.add_argument('--attack', '--atk', dest='attack', default=None)
    parser.add_argument('--defense', '--def', dest='defense', default=None)
    parser.add_argument('--special-attack', '--spatk', dest='special-attack', default=None)
    parser.add_argument('--special-defense', '--spdef', dest='special-defense', default=None)
    parser.add_argument('--speed', dest='speed', default=None)
    parser.add_argument('--hp', dest='hp', default=None)



def command_search(parser, args):