# Path: pulp_auto/pulp.py
# class Request(object):
#     pulp_path = pulp_path
#     '''a callable request compatible with Pulp.send''' 
#     def __init__(self, method, path='/', data={}, headers=cidict({'content-type': 'application/json'}),
#             params={}):
#         self.method = method
#         self.path = path
#         if 'content-type' in headers and headers['content-type'] == 'application/json':
#             self.data = json.dumps(data)
#         else:
#             self.data = data
#         self.headers = headers
#         self.params = params
# 
#     def __call__(self, url, auth):
#         return requests.Request(
#             self.method,
#             normalize_url(path_join(url, self.pulp_path, self.path)),
#             params=self.params,
#             auth=auth,
#             data=self.data,
#             headers=self.headers
#         ).prepare()
# 
#     def __repr__(self):
#         return self.__class__.__name__ + "(%r, %r, data=%r, headers=%r)" % (self.method, self.path, self.data, self.headers)


from unit import (AbstractUnit, RpmUnit, UnitFactory)
from pulp_auto.pulp import Request
class Orphans(object):
    '''The content/orphans/ container handler'''
    path = '/content/orphans/'

    @classmethod
    def info(cls, pulp):
        return pulp.send(Request('GET', cls.path)).json()

    @classmethod
    def delete(cls, pulp):
        '''delete all orphans no matter the orphan type'''
        return pulp.send(Request('DELETE', cls.path))

    @classmethod
    def get(cls, pulp):
        '''get all orphans according to their type'''
        info = cls.info(pulp)
        ret = {}
        for orphan_type in info.keys():
            assert orphan_type in UnitFactory.type_map.orphans, "Unknown orphan type: %s" % orphan_type
            ret[orphan_type] = UnitFactory.type_map.orphans[orphan_type].list(pulp)
        return ret

    @classmethod
    def delete_by_type_id(
        cls,
        pulp,
        data,
        path='/content/actions/delete_orphans/'
    ):

# Path: pulp_auto/pulp.py
# class Request(object):
#     pulp_path = pulp_path
#     '''a callable request compatible with Pulp.send''' 
#     def __init__(self, method, path='/', data={}, headers=cidict({'content-type': 'application/json'}),
#             params={}):
#         self.method = method
#         self.path = path
#         if 'content-type' in headers and headers['content-type'] == 'application/json':
#             self.data = json.dumps(data)
#         else:
#             self.data = data
#         self.headers = headers
#         self.params = params
# 
#     def __call__(self, url, auth):
#         return requests.Request(
#             self.method,
#             normalize_url(path_join(url, self.pulp_path, self.path)),
#             params=self.params,
#             auth=auth,
#             data=self.data,
#             headers=self.headers
#         ).prepare()
# 
#     def __repr__(self):
#         return self.__class__.__name__ + "(%r, %r, data=%r, headers=%r)" % (self.method, self.path, self.data, self.headers)


# Path: pulp_auto/units/orphan.py
from unit import (AbstractUnit, RpmUnit, UnitFactory)
from pulp_auto.pulp import Request

class Orphans(object):
    '''The content/orphans/ container handler'''
    path = '/content/orphans/'

    @classmethod
    def info(cls, pulp):
        return pulp.send(Request('GET', cls.path)).json()

    @classmethod
    def delete(cls, pulp):
        '''delete all orphans no matter the orphan type'''
        return pulp.send(Request('DELETE', cls.path))

    @classmethod
    def get(cls, pulp):
        '''get all orphans according to their type'''
        info = cls.info(pulp)
        ret = {}
        for orphan_type in info.keys():
            assert orphan_type in UnitFactory.type_map.orphans, "Unknown orphan type: %s" % orphan_type
            ret[orphan_type] = UnitFactory.type_map.orphans[orphan_type].list(pulp)
        return ret

    @classmethod
    def delete_by_type_id(
        cls,
        pulp,
        data,
        path='/content/actions/delete_orphans/'
    ):

        return pulp.send(Request('POST', path=path, data=data))