"""Contains classes and methods relating to narratives.

Narrative hold collections of overridden parameter data. During model setup,
a user compiles a number of narrative files which contains a list of parameter
names and values. These are assigned to a narrative set during a model run
and the Narrative object holds this information at runtime.
"""


class Narrative(object):
    """Holds information relating to parameters from a collection of narrative policies

    Arguments
    ---------
    name : str
    description :str
    narrative_set : str

    Example
    --------
    >>> narrative = Narrative('Energy Demand - High Tech',
                                  'A description',
                                  'technology')
    """
    def __init__(self, name, description, narrative_set):
        self._name = name
        self._description = description
        self._narrative_set = narrative_set

        self._data = {}

    @property
    def data(self):
        """The narrative data keyed by model name or ``global``

        Returns
        -------
        dict
            A nested dictionary containing the narrative data::

                {'global': [{'global_parameter': 'value'}],
                 'model_name': [{'model_parameter': 'value'},
                                {'model_parameter_two': 'value'}
                                ]
                }
        """
        return self._data

    @data.setter
    def data(self, data):
        """Add data to the Narrative object

        Arguments
        ---------
        data : dict
            A dictionary of overridden parameter values

        Example
        -------
        >>> narrative_data = {'global': [{'name': 'parameter_name',
                                          'value': 42}]}
        >>> narrative = Narrative('Energy Demand - High Tech',
                                      'A description',
                                      'technology')
        >>> narrative.add_data(narrative_data)
        """
        if isinstance(data, dict):
            self._data.update(data)
        else:
            raise TypeError("Expected a dict of parameter values")

    def as_dict(self):
        """Serialise the narrative data

        Returns
        -------
        dict
            A dictionary of serialised narrative metadata::

                {'name': 'a_name',
                 'description': 'a description',
                 'narrative_set': 'a_narrative_set'}

        """
        config = {'name': self._name,
                  'description': self._description,
                  'narrative_set': self._narrative_set}
        return config

    def __eq__(self, other):
        return self.as_dict() == other.as_dict() and \
            self.data == other.data

@@ -1161,27 +1161,73 @@
        %7B
-'global': %5B
+%0A                    'global': %5B%0A                        
 %7B'global
@@ -1251,11 +1251,35 @@
 ue'%7D
-%5D,%0A
+%0A                    %5D,%0A   
     
@@ -1306,16 +1306,41 @@
 name': %5B
+%0A                        
 %7B'model_
@@ -1361,24 +1361,16 @@
 alue'%7D,%0A
-        
         
@@ -1414,36 +1414,24 @@
 ': 'value'%7D%0A
-            
             
@@ -1764,28 +1764,58 @@
  = %7B
-'global': %5B%7B'name': 
+%0A                'global': %5B%0A                    %7B
 'par
@@ -1822,25 +1822,29 @@
 ameter_name'
-,
+: 42%7D
 %0A           
@@ -1840,32 +1840,34 @@
                 
+%5D%0A
                 
@@ -1866,35 +1866,8 @@
     
-              'value': 42%7D%5D
 %7D%0A  
@@ -1890,32 +1890,49 @@
 ive = Narrative(
+%0A                
 'Energy Demand -
@@ -1960,38 +1960,16 @@
         
-         
-             
 'A descr
@@ -1977,38 +1977,16 @@
 ption',%0A
-                      
         

Format docstrings for Narrative