"""Provides "constants" to use for ``only`` and ``exclude`` arguments of ``FieldsIterator``"""


# pylint: disable=invalid-name
class _FieldTypes:
    """Provides "constants" to use for ``only`` and ``exclude`` arguments of ``FieldsIterator``

    Attributes
    ----------
    SIMPLE : str
        The attribute to use for simple fields
    FK : str
        The attribute to use for foreign keys (and one to one fields)
    M2M : str
        The attribute to use for many to many fields
    REVERSE_FK : str
        The attribute to use for reverse foreign keys, ie foreign keys defined on another model,
        pointing on the model we use
    REVERSE_M2M : str
        The attribute to use for reverse many to many fields, ie many to many fields defined on
        another model, pointing on the model we use
    REVERSE_O2O : str
        The attribute to use for reverse one to one fields, ie one to one fields defined on
        another model, pointing on the model we use
    allowed_types : list(str)
        List with all allowed types that can be used.
        Used to check validity of ``only`` and ``exclude`` arguments in the iterator, and to
        go through the whole list of fields in a consistent order.

    """

    SIMPLE = 'simple_fields'

    FK = 'foreign_keys'
    M2M = 'manytomany_fields'

    REVERSE_FK = 'reverse_foreign_keys'
    REVERSE_M2M = 'reverse_manytomany_fields'
    REVERSE_O2O = 'reverse_onetoone_fields'

    # simple fields, then fields that point to a simple instance, than fields that point to many
    allowed_types = [SIMPLE, FK, REVERSE_O2O, M2M, REVERSE_M2M, REVERSE_FK]

    def __contains__(self, item):
        """Check if the given item is in the allowed types

        Parameters
        ----------
        item
            The item to search for in ``allowed_types``

        Returns
        -------
        bool
            ``True`` if `item` is in ``allowed_types`, otherwise ``False``

        """

        return item in self.allowed_types


# Provide an instance instead of the class (to make ``__contains__`` work)
FieldTypes = _FieldTypes()
