a
    gh	                     @   s0   d dl mZmZ d dlmZ G dd deZdS )    )StringField	ListField)TimestampedMixinc                       st   e Zd ZdZedddZeddZeeddd	dZd
d Z	e
dddZe
dddZdd Z fddZ  ZS )Rolea4  
    Role model for defining user roles and permissions.

    Attributes:
        name (str): The name of the role (required).
        description (str): A description of the role.
    Methods:
        __str__(): Return the name of the role as a string representation.
        add_permission(permission: str): Add a permission to the role.
        remove_permission(permission: str): Remove a permission from the role.
        get_permissions(): Get the list of permissions associated with the role.
        to_dict(): Convert the role object to a dictionary.
    TzThe name of the role.)required	help_textzA description of the role.)r   2   )
max_lengthz/A list of permissions associated with the role.c                 C   s   | j S )z
        Return the name of the role as a string representation.

        Returns:
            str: The name of the role.
        )nameself r   /app/app/models/role.py__str__   s    zRole.__str__)
permissionc                 C   s   || j vr| j | dS )z
        Add a permission to the role.

        Args:
            permission (str): The permission to add.

        Returns:
            None
        N)permissionsappendr   r   r   r   r   add_permission$   s    

zRole.add_permissionc                 C   s   || j v r| j | dS )z
        Remove a permission from the role.

        Args:
            permission (str): The permission to remove.

        Returns:
            None
        N)r   remover   r   r   r   remove_permission1   s    

zRole.remove_permissionc                 C   s   | j S )z
        Get the list of permissions associated with the role.

        Returns:
            list: A list of permissions.
        )r   r   r   r   r   get_permissions>   s    zRole.get_permissionsc                    s   t t|  }|dd |S )z7
        Convert the document to a dictionary.
        idN)superr   to_dictpop)r   Z	role_dict	__class__r   r   r   G   s    zRole.to_dict)__name__
__module____qualname____doc__r   r
   descriptionr   r   r   strr   r   r   r   __classcell__r   r   r   r   r      s   
		r   N)mongoenginer   r   app.models.baser   r   r   r   r   r   <module>   s   