#
# <one line to give the library's name and an idea of what it does.>
# Copyright (C) 2014    <copyright holder> <email>
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.    See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.    If not, see <http://www.gnu.org/licenses/>.
# 
#

import abc

class EdgeBuiderInterface(object):
  """!
  Interface for all edge builders. Method to adding edges (add_edges) 
  must be implemented in each child.
  """
  __metaclass__ = abc.ABCMeta

  def __init__(self, str_name, chan_name = None, set_name = None):
    """
    Constructor sets the members to given values

    @param str_name: String-like name of egde builder
    @param chan_name: Name of channel
    @param set_name: Name of set of relations
    """
    self._str_name = str_name
    self._chan_name = chan_name
    self._set_name = set_name

  def __str__(self):
    """
    String like representation of edge builder

    @return string representation of edge builder
    """
    if self._chan_name:
      return '%s:%s' % (self._str_name, self._chan_name)
    return '%s:%s' % (self._str_name, self._set_name)

  def exists_edge(self, g, src, trg, label):
    """!
    Function checks existings of labelled edge into given graph.

    @param g Graph
    @type g: networkx.Graph/networkx.DiGraph/networkx.MultiDiGraph
    @param src Source node into graph 
    @type src: netowrkx.node
    @param trg Target node into graph 
    @type trg: netowrkx.node
    @return True if edge (src, trg) with label (label) exists into grapg g
    @rtype: Boolean
    """
    for (f, t, d) in g.edges(src, data=True):
      if (f, t, label in d.values()) == (src, trg, True):
        return True
    return False

  @abc.abstractmethod
  def add_edges(self, base_graph):
    """!
    Method to adding edges between existing nodes into graph.

    Base on type of edge builder, the edges are added between existing nodes 
    into given graph.

    @param base_graph: a base graph for that the edges will are added
    """
    pass