
__all__ = ["mixin", "mixin_bowl", "mixin_ingredient"]

def mixin(base_class, mixin_class, first = True):
    if first:
        _mixin_first(base_class, mixin_class)
    else:
        _mixin_last(base_class, mixin_class)

def _mixin_first(base_class, mixin_class):
    if hasattr(base_class, "mixin_first"):
        base_class.mixin_first(mixin_class)
    else:
        if base_class.__bases__ == (object,):
            base_class.__bases__  =  (mixin_class,)
        else:
            base_class.__bases__  = (mixin_class,) + base_class.__bases__

def _mixin_last(base_class, mixin_class):
    if hasattr(base_class, "mixin_last"):
        base_class.mixin_last(mixin_class)
    else:
        if base_class.__bases__ == (object,):
            base_class.__bases__  =  (mixin_class,)
        else:
            base_class.__bases__  = base_class.__bases__ + (mixin_class,) 

            
class mixin_ingredient(object):
    pass

class meta_mixin_bowl(type):
    def mixin_first(cls, mixin_class):
        if cls.__bases__ == (object,):
            cls.__bases__  =  (mixin_class,)
        else:
            cls.__bases__  =  (mixin_class,) + cls.__bases__ 

    def mixin_last(cls, mixin_class):
        if cls.__bases__ == (object,):
            cls.__bases__  =  (mixin_class,)
        else:
            cls.__bases__  = cls.__bases__ + (mixin_class,) 

    def mixin(cls, mixin_class, first = True):
        if first:
            cls.mixin_first(mixin_class)
        else:
            cls.mixin_last(mixin_class)
    

class mixin_bowl(object):
    __metaclass__ = meta_mixin_bowl
    pass
    