#!/usr/bin/env python
# -*- coding: utf-8 -*-


class Behavior(object):
    def __init__(self, pairs=None, actions=None, resources=None):
        self.pairs = list(pairs) if pairs else []
        self.actions = list(actions) if actions else []
        self.resources = list(resources) if resources else []

    def __add__(self, other):
        pairs = set(self.pairs + list(other.pairs))
        actions = set(self.actions + list(other.actions))
        resources = set(self.resources + list(other.resources))
        return Behavior(pairs=pairs, actions=actions, resources=resources)
    
    def parse_json(self, json_dict):
        self.pairs = json_dict.get("pairs")
        self.actions = json_dict.get("actions")
        self.resources = json_dict.get("resources")

        return self
    
    def to_json(self):
        return self.__attrs()

    def __attrs(self):
        attrs = dict()
        attrs["pairs"] = self.pairs
        attrs["actions"] = self.actions
        attrs["resources"] = self.resources
        return attrs
    
    def __str__(self):
        return str({"pairs": self.pairs, "actions": self.actions,
                    "resources": self.resources})

