from .es_query import HQESQuery
from . import filters


class DomainES(HQESQuery):
    index = 'domains'

    @property
    def builtin_filters(self):
        return [
            non_test_domains,
            incomplete_domains,
            real_domains,
            commcare_domains,
            commconnect_domains,
            commtrack_domains,
            created,
            in_domains,
        ] + super(DomainES, self).builtin_filters


def non_test_domains():
    return filters.term("is_test", [False, "none"])


def incomplete_domains():
    return filters.OR(filters.missing("country"),
                      filters.missing("internal.area"),
                      filters.missing("internal.initiative"),
                      filters.missing("internal.notes"),
                      filters.missing("internal.organization_name"),
                      filters.missing("internal.platform"),
                      filters.missing("internal.phone_model"),
                      filters.missing("internal.project_manager"),
                      filters.missing("internal.project_state"),
                      filters.missing("internal.sub_area"),
                      )


def real_domains():
    return filters.term("is_test", False)


def commcare_domains():
    return filters.AND(filters.term("commconnect_enabled", False),
                       filters.term("commtrack_enabled", False))


def commconnect_domains():
    return filters.term("commconnect_enabled", True)


def commtrack_domains():
    return filters.term("commtrack_enabled", True)


def created(gt=None, gte=None, lt=None, lte=None):
    return filters.date_range('date_created', gt, gte, lt, lte)


def in_domains(domains):
    return filters.term('name', list(domains))

@@ -589,17 +589,19 @@
 (%22countr
-y
+ies
 %22),%0A    

Change country to countries in missing filter