# Path: tenable_io/api/base.py
# class BaseApi(object):
# 
#     def __init__(self, client):
#         self._client = client
# 
# Path: tenable_io/api/base.py
# class BaseRequest(object):
# 
#     def as_payload(self, filter_=None):
#         return payload_filter(self.__dict__, filter_)
# 
# Path: tenable_io/api/models.py
# class AccessGroup(BaseModel):
# 
#     def __init__(
#             self,
#             container_uuid=None,
#             created_at=None,
#             updated_at=None,
#             id=None,
#             name=None,
#             all_assets=None,
#             all_users=None,
#             status=None,
#             rules=None,
#             principals=None,
#             version=None,
#             created_by_uuid=None,
#             updated_by_uuid=None,
#             updated_by_name=None,
#             created_by_name=None,
#             processing_percent_complete=None
#     ):
#         self._rules = None
#         self._principals = None
#         self.container_uuid = container_uuid
#         self.created_at = created_at
#         self.updated_at = updated_at
#         self.id = id
#         self.name = name
#         self.all_assets = all_assets
#         self.all_users = all_users
#         self.status = status
#         self.rules = rules
#         self.principals = principals
#         self.version = version
#         self.created_by_uuid = created_by_uuid
#         self.updated_by_uuid = updated_by_uuid
#         self.updated_by_name = updated_by_name
#         self.created_by_name = created_by_name
#         self.processing_percent_complete = processing_percent_complete
# 
#     @property
#     def rules(self):
#         return self._rules
# 
#     @rules.setter
#     @BaseModel._model_list(AssetRule)
#     def rules(self, rules):
#         self._rules = rules
# 
#     @property
#     def principals(self):
#         return self._principals
# 
#     @principals.setter
#     @BaseModel._model_list(AssetRulePrincipal)
#     def principals(self, principals):
#         self._principals = principals
# 
# class AccessGroupList(BaseModel):
# 
#     def __init__(
#             self,
#             access_groups=None,
#             pagination=None
#     ):
#         self._access_groups = None
#         self._pagination = None
#         self.access_groups = access_groups
#         self.pagination = pagination
# 
#     @property
#     def access_groups(self):
#         return self._access_groups
# 
#     @access_groups.setter
#     @BaseModel._model_list(AccessGroup)
#     def access_groups(self, access_groups):
#         self._access_groups = access_groups
# 
#     @property
#     def pagination(self):
#         return self._pagination
# 
#     @pagination.setter
#     @BaseModel._model(FilterPagination)
#     def pagination(self, pagination):
#         self._pagination = pagination
# 
# class AssetRule(BaseModel):
# 
#     def __init__(
#             self,
#             type=None,
#             operator=None,
#             terms=None
#     ):
#         self.type = type
#         self.operator = operator
#         self.terms = terms
# 
# class AssetRuleFilter(Filter):
# 
#     def __init__(
#             self,
#             placeholder=None,
#     ):
#         self.placeholder = placeholder
# 
# class AssetRulePrincipal(BaseModel):
# 
#     def __init__(
#             self,
#             type=None,
#             principal_id=None,
#             principal_name=None
#     ):
#         self.type = type
#         self.principal_id = principal_id
#         self.principal_name = principal_name
# 
# class Filters(BaseModel):
# 
#     def __init__(
#             self,
#             filters=None,
#             sort=None,
#             wildcard_fields=None
#     ):
#         self._filters = None
#         self.filters = filters
#         self.sort = sort
#         self.wildcard_fields = wildcard_fields
# 
#     @property
#     def filters(self):
#         return self._filters
# 
#     @filters.setter
#     @BaseModel._model_list(Filter)
#     def filters(self, filters):
#         self._filters = filters


from json import loads
from tenable_io.api.base import BaseApi
from tenable_io.api.base import BaseRequest
from tenable_io.api.models import AccessGroup, AccessGroupList, AssetRule, AssetRuleFilter, AssetRulePrincipal, Filters
            If 'false', only specified users have Can View access to the assets defined in the rules parameter.
            You define which users or user groups have access in the principals parameter of the request.
        :type all_users: boolean
        :param rules: An array of asset rules. Tenable.io uses these rules to assign assets to the access group.
            You can only add rules to access groups if the all_assets parameter is set to 'false'.
        :type rules: list
        :param principals: A list of principals. Each representing a user or user group assigned to the access group.
            Data in this array is handled based on the all_users parameter. If all_users is 'true',
            any principal data is ignored and you can omit this parameter.
            If all_users is 'false', the principal data is added to the access group.
        :type principals: list
        """
        for r in rules:
            assert isinstance(r, AssetRule)

        self.name = name
        self.all_assets = all_assets
        self.all_users = all_users
        self.rules = rules
        self.principals = principals

    def as_payload(self, filter_=None):
        payload = super(AccessGroupRequest, self).as_payload(True)
        rule_list = []
        for r in self.rules:
            rule_list.append(r.as_payload())
        payload.__setitem__('rules', rule_list)
        if not self.all_users and self.principals:
            principal_list = []
            for p in self.principals:

# Path: tenable_io/api/base.py
# class BaseApi(object):
# 
#     def __init__(self, client):
#         self._client = client
# 
# Path: tenable_io/api/base.py
# class BaseRequest(object):
# 
#     def as_payload(self, filter_=None):
#         return payload_filter(self.__dict__, filter_)
# 
# Path: tenable_io/api/models.py
# class AccessGroup(BaseModel):
# 
#     def __init__(
#             self,
#             container_uuid=None,
#             created_at=None,
#             updated_at=None,
#             id=None,
#             name=None,
#             all_assets=None,
#             all_users=None,
#             status=None,
#             rules=None,
#             principals=None,
#             version=None,
#             created_by_uuid=None,
#             updated_by_uuid=None,
#             updated_by_name=None,
#             created_by_name=None,
#             processing_percent_complete=None
#     ):
#         self._rules = None
#         self._principals = None
#         self.container_uuid = container_uuid
#         self.created_at = created_at
#         self.updated_at = updated_at
#         self.id = id
#         self.name = name
#         self.all_assets = all_assets
#         self.all_users = all_users
#         self.status = status
#         self.rules = rules
#         self.principals = principals
#         self.version = version
#         self.created_by_uuid = created_by_uuid
#         self.updated_by_uuid = updated_by_uuid
#         self.updated_by_name = updated_by_name
#         self.created_by_name = created_by_name
#         self.processing_percent_complete = processing_percent_complete
# 
#     @property
#     def rules(self):
#         return self._rules
# 
#     @rules.setter
#     @BaseModel._model_list(AssetRule)
#     def rules(self, rules):
#         self._rules = rules
# 
#     @property
#     def principals(self):
#         return self._principals
# 
#     @principals.setter
#     @BaseModel._model_list(AssetRulePrincipal)
#     def principals(self, principals):
#         self._principals = principals
# 
# class AccessGroupList(BaseModel):
# 
#     def __init__(
#             self,
#             access_groups=None,
#             pagination=None
#     ):
#         self._access_groups = None
#         self._pagination = None
#         self.access_groups = access_groups
#         self.pagination = pagination
# 
#     @property
#     def access_groups(self):
#         return self._access_groups
# 
#     @access_groups.setter
#     @BaseModel._model_list(AccessGroup)
#     def access_groups(self, access_groups):
#         self._access_groups = access_groups
# 
#     @property
#     def pagination(self):
#         return self._pagination
# 
#     @pagination.setter
#     @BaseModel._model(FilterPagination)
#     def pagination(self, pagination):
#         self._pagination = pagination
# 
# class AssetRule(BaseModel):
# 
#     def __init__(
#             self,
#             type=None,
#             operator=None,
#             terms=None
#     ):
#         self.type = type
#         self.operator = operator
#         self.terms = terms
# 
# class AssetRuleFilter(Filter):
# 
#     def __init__(
#             self,
#             placeholder=None,
#     ):
#         self.placeholder = placeholder
# 
# class AssetRulePrincipal(BaseModel):
# 
#     def __init__(
#             self,
#             type=None,
#             principal_id=None,
#             principal_name=None
#     ):
#         self.type = type
#         self.principal_id = principal_id
#         self.principal_name = principal_name
# 
# class Filters(BaseModel):
# 
#     def __init__(
#             self,
#             filters=None,
#             sort=None,
#             wildcard_fields=None
#     ):
#         self._filters = None
#         self.filters = filters
#         self.sort = sort
#         self.wildcard_fields = wildcard_fields
# 
#     @property
#     def filters(self):
#         return self._filters
# 
#     @filters.setter
#     @BaseModel._model_list(Filter)
#     def filters(self, filters):
#         self._filters = filters


# Path: tenable_io/api/access_groups.py
from json import loads
from tenable_io.api.base import BaseApi
from tenable_io.api.base import BaseRequest
from tenable_io.api.models import AccessGroup, AccessGroupList, AssetRule, AssetRuleFilter, AssetRulePrincipal, Filters

            If 'false', only specified users have Can View access to the assets defined in the rules parameter.
            You define which users or user groups have access in the principals parameter of the request.
        :type all_users: boolean
        :param rules: An array of asset rules. Tenable.io uses these rules to assign assets to the access group.
            You can only add rules to access groups if the all_assets parameter is set to 'false'.
        :type rules: list
        :param principals: A list of principals. Each representing a user or user group assigned to the access group.
            Data in this array is handled based on the all_users parameter. If all_users is 'true',
            any principal data is ignored and you can omit this parameter.
            If all_users is 'false', the principal data is added to the access group.
        :type principals: list
        """
        for r in rules:
            assert isinstance(r, AssetRule)

        self.name = name
        self.all_assets = all_assets
        self.all_users = all_users
        self.rules = rules
        self.principals = principals

    def as_payload(self, filter_=None):
        payload = super(AccessGroupRequest, self).as_payload(True)
        rule_list = []
        for r in self.rules:
            rule_list.append(r.as_payload())
        payload.__setitem__('rules', rule_list)
        if not self.all_users and self.principals:
            principal_list = []
            for p in self.principals:

                assert isinstance(p, AssetRulePrincipal)