# Path: tenable_io/api/base.py
# class BaseApi(object):
# 
#     def __init__(self, client):
#         self._client = client
# 
# class BaseRequest(object):
# 
#     def as_payload(self, filter_=None):
#         return payload_filter(self.__dict__, filter_)
# 
# Path: tenable_io/api/models.py
# class User:
#     # User Roles
#     PERMISSION_BASIC = 16
#     PERMISSION_SCAN_OPERATOR = 24
#     PERMISSION_STANDARD = 32
#     PERMISSION_SCAN_MANAGER = 40
#     PERMISSION_ADMINISTRATOR = 64
# 
# class UserKeys(BaseModel):
# 
#     def __init__(
#             self,
#             access_key=None,
#             secret_key=None,
#     ):
#         self.access_key = access_key
#         self.secret_key = secret_key
# 
#     @classmethod
#     def from_dict(cls, dict_):
#         # Because API uses camelCase for some reason; normalize to underscore here.
#         if 'accessKey' in dict_:
#             dict_['access_key'] = dict_.pop('accessKey')
#         if 'secretKey' in dict_:
#             dict_['secret_key'] = dict_.pop('secretKey')
#         return super(UserKeys, cls).from_dict(dict_)
# 
#     def as_payload(self, filter_=None):
#         # Because API uses camelCase for some reason; normalize to underscore here.
#         payload = self.as_payload(filter_)
#         if 'access_key' in payload:
#             payload['accessKey'] = payload.pop('access_key')
#         if 'secret_key' in payload:
#             payload['secretKey'] = payload.pop('secret_key')
#         return payload
# 
# class UserList(BaseModel):
# 
#     def __init__(
#             self,
#             users=None,
#     ):
#         self._users = None
#         self.users = users
# 
#     @property
#     def users(self):
#         return self._users
# 
#     @users.setter
#     @BaseModel._model_list(User)
#     def users(self, users):
#         self._users = users
# 
# class UserAuthorizations(BaseModel):
# 
#     def __init__(
#             self,
#             account_uuid=None,
#             user_uuid=None,
#             api_permitted=None,
#             password_permitted=None,
#             saml_permitted=None
#     ):
#         self.account_uuid = account_uuid
#         self.user_uuid = user_uuid
#         self.api_permitted = api_permitted
#         self.password_permitted = password_permitted
#         self.saml_permitted = saml_permitted


from json import loads
from tenable_io.api.base import BaseApi, BaseRequest
from tenable_io.api.models import User, UserKeys, UserList, UserAuthorizations

    def delete(self, user_id):
        """Delete a user.

        :param user_id: The user ID.
        :raise TenableIOApiException:  When API error is encountered.
        :return: True if successful.
        """
        self._client.delete('users/%(user_id)s', {'user_id': user_id})
        return True

    def password(self, user_id, password):
        """Change the password for the given user.

        :param user_id: The user ID.
        :param password: Current password for the user.
        :raise TenableIOApiException:  When API error is encountered.
        :return: True if successful.
        """
        self._client.put('users/%(user_id)s/chpasswd', {'password': password}, {'user_id': user_id})
        return True

    def details(self, user_id):
        """Return details for the given user.

        :param user_id: The user ID.
        :raise TenableIOApiException:  When API error is encountered.
        :return: An instance of :class:`tenable_io.api.models.User`
        """
        response = self._client.get('users/%(user_id)s', {'user_id': user_id})

# Path: tenable_io/api/base.py
# class BaseApi(object):
# 
#     def __init__(self, client):
#         self._client = client
# 
# class BaseRequest(object):
# 
#     def as_payload(self, filter_=None):
#         return payload_filter(self.__dict__, filter_)
# 
# Path: tenable_io/api/models.py
# class User:
#     # User Roles
#     PERMISSION_BASIC = 16
#     PERMISSION_SCAN_OPERATOR = 24
#     PERMISSION_STANDARD = 32
#     PERMISSION_SCAN_MANAGER = 40
#     PERMISSION_ADMINISTRATOR = 64
# 
# class UserKeys(BaseModel):
# 
#     def __init__(
#             self,
#             access_key=None,
#             secret_key=None,
#     ):
#         self.access_key = access_key
#         self.secret_key = secret_key
# 
#     @classmethod
#     def from_dict(cls, dict_):
#         # Because API uses camelCase for some reason; normalize to underscore here.
#         if 'accessKey' in dict_:
#             dict_['access_key'] = dict_.pop('accessKey')
#         if 'secretKey' in dict_:
#             dict_['secret_key'] = dict_.pop('secretKey')
#         return super(UserKeys, cls).from_dict(dict_)
# 
#     def as_payload(self, filter_=None):
#         # Because API uses camelCase for some reason; normalize to underscore here.
#         payload = self.as_payload(filter_)
#         if 'access_key' in payload:
#             payload['accessKey'] = payload.pop('access_key')
#         if 'secret_key' in payload:
#             payload['secretKey'] = payload.pop('secret_key')
#         return payload
# 
# class UserList(BaseModel):
# 
#     def __init__(
#             self,
#             users=None,
#     ):
#         self._users = None
#         self.users = users
# 
#     @property
#     def users(self):
#         return self._users
# 
#     @users.setter
#     @BaseModel._model_list(User)
#     def users(self, users):
#         self._users = users
# 
# class UserAuthorizations(BaseModel):
# 
#     def __init__(
#             self,
#             account_uuid=None,
#             user_uuid=None,
#             api_permitted=None,
#             password_permitted=None,
#             saml_permitted=None
#     ):
#         self.account_uuid = account_uuid
#         self.user_uuid = user_uuid
#         self.api_permitted = api_permitted
#         self.password_permitted = password_permitted
#         self.saml_permitted = saml_permitted


# Path: tenable_io/api/users.py
from json import loads
from tenable_io.api.base import BaseApi, BaseRequest
from tenable_io.api.models import User, UserKeys, UserList, UserAuthorizations


    def delete(self, user_id):
        """Delete a user.

        :param user_id: The user ID.
        :raise TenableIOApiException:  When API error is encountered.
        :return: True if successful.
        """
        self._client.delete('users/%(user_id)s', {'user_id': user_id})
        return True

    def password(self, user_id, password):
        """Change the password for the given user.

        :param user_id: The user ID.
        :param password: Current password for the user.
        :raise TenableIOApiException:  When API error is encountered.
        :return: True if successful.
        """
        self._client.put('users/%(user_id)s/chpasswd', {'password': password}, {'user_id': user_id})
        return True

    def details(self, user_id):
        """Return details for the given user.

        :param user_id: The user ID.
        :raise TenableIOApiException:  When API error is encountered.
        :return: An instance of :class:`tenable_io.api.models.User`
        """
        response = self._client.get('users/%(user_id)s', {'user_id': user_id})

        return User.from_json(response.text)