# -*- coding: utf-8 -*-

"""Internal DSL functions for edges."""

from .utils import entity
from ..constants import (
    ACTIVITY, BEL_DEFAULT_NAMESPACE, DEGRADATION, EFFECT, FROM_LOC, LOCATION, MODIFIER, TO_LOC,
    TRANSLOCATION,
)

__all__ = [
    'activity',
    'degradation',
    'translocation',
    'extracellular',
    'intracellular',
    'secretion',
    'cell_surface_expression',
]

intracellular = entity(name='intracellular', namespace='GOCC')
extracellular = entity(name='extracellular space', namespace='GOCC')
surface = entity(name='cell surface', namespace='GOCC')


def _activity_helper(modifier, location=None):
    """Make an activity dictionary.

    :param str modifier:
    :param Optional[dict] location: An entity from :func:`pybel.dsl.entity`
    :rtype: dict
    """
    rv = {MODIFIER: modifier}

    if location:
        rv[LOCATION] = location

    return rv


def activity(name=None, namespace=None, identifier=None, location=None):
    """Make a subject/object modifier dictionary.

    :param str name: The name of the activity. If no namespace given, uses BEL default namespace
    :param Optional[str] namespace: The namespace of the activity
    :param Optional[str] identifier: The identifier of the name in the database
    :param Optional[dict] location: An entity from :func:`pybel.dsl.entity` representing the location of the node
    :rtype: dict
    """
    rv = _activity_helper(ACTIVITY, location=location)

    if name or (namespace and identifier):
        rv[EFFECT] = entity(
            namespace=(namespace or BEL_DEFAULT_NAMESPACE),
            name=name,
            identifier=identifier
        )

    return rv


def degradation(location=None):
    """Make a degradation dictionary.

    :param Optional[dict] location: An entity from :func:`pybel.dsl.entity` representing the location of the node
    :rtype: dict
    """
    return _activity_helper(DEGRADATION, location=location)


def translocation(from_loc, to_loc):
    """Make a translocation dictionary.

    :param dict from_loc: An entity dictionary from :func:`pybel.dsl.entity`
    :param dict to_loc: An entity dictionary from :func:`pybel.dsl.entity`
    :rtype: dict
    """
    rv = _activity_helper(TRANSLOCATION)
    rv[EFFECT] = {
        FROM_LOC: from_loc,
        TO_LOC: to_loc
    }
    return rv


def secretion():
    """Make a secretion translocation dictionary.

    This is a convenient wrapper representing the :func:`translocation` from the intracellular location to the
    extracellular space.

    :rtype: dict
    """
    return translocation(
        from_loc=intracellular,
        to_loc=extracellular
    )


def cell_surface_expression():
    """Make a cellular surface expression translocation dictionary.

    This is a convenient wrapper representing the :func:`translocation` from the intracellular location to the cell
    surface.

    :rtype: dict
    """
    return translocation(
        from_loc=intracellular,
        to_loc=surface,
    )

@@ -387,16 +387,32 @@
 ssion',%0A
+    'location',%0A
 %5D%0A%0Aintra
@@ -3005,12 +3005,1398 @@
 face,%0A    )%0A
+%0A%0Adef location(identifier):%0A    %22%22%22Make a location object modifier dictionary.%0A%0A    :param entity identifier: A namespace/name/identifier pair%0A%0A    Usage:%0A%0A    X increases the abundance of Y in the cytoplasm%0A%0A    .. code-block:: python%0A%0A        from pybel import BELGraph%0A        from pybel.dsl import protein, location%0A%0A        graph = BELGraph()%0A%0A        source = protein('HGNC', 'IRAK1')%0A        target = protein('HGNC', 'IRF7, variants=%5B%0A            pmod('Ph', 'Ser', 477), pmod('Ph', 'Ser', 479),%0A        %5D)%0A        graph.add_increases(%0A            source,%0A            target,%0A            citation=...,%0A            evidence=...,%0A            object_modifier=location(entity(namespace='GO', name='cytosol', identifier='GO:0005829')),%0A        )%0A%0A    X increases the kinase activity of Y in the cytoplasm. In this case, the :func:%60activity%60 function takes a location as%0A    an optional argument.%0A%0A    .. code-block:: python%0A%0A        from pybel import BELGraph%0A        from pybel.dsl import protein, location%0A%0A        graph = BELGraph()%0A%0A        source = ...%0A        target = ...%0A        graph.add_increases(%0A            source,%0A            target,%0A            citation=...,%0A            evidence=...,%0A            object_modifier=activity('kin', location=entity(namespace='GO', name='cytosol', identifier='GO:0005829')),%0A        )%0A    %22%22%22%0A    return %7B%0A        LOCATION: identifier%0A    %7D%0A

Update documentation for location