o
    wi                     @  s   d Z ddlmZ ddlmZ ddlmZmZ ddlm	Z	 ddl
mZ ddlmZ er2dd	lmZmZ G d
d deZG dd deZdS )a-  W&B Public API for managing teams and team members.

This module provides classes for managing W&B teams and their members.

Note:
    This module is part of the W&B Public API and provides methods to manage
    teams and their members. Team management operations require appropriate
    permissions.
    )annotations)Mapping)TYPE_CHECKINGAny)Self)gql)Attrs   )ApiRetryingClientc                      s2   e Zd ZdZd fdd	Zd
d Zdd Z  ZS )MemberzA member of a team.

    Args:
        client (`wandb.apis.internal.Api`): The client instance to use
        team (str): The name of the team this member belongs to
        attrs (dict): The member attributes
    clientr   teamstrattrsMapping[str, Any]c                   s   t  | || _|| _d S N)super__init___clientr   )selfr   r   r   	__class__ K/home/ubuntu/.local/lib/python3.10/site-packages/wandb/apis/public/teams.pyr   "   s   
zMember.__init__c                 C  sl   ddl m} ddlm}m} z| jt|| j| j	d}W n
 |y(   Y dS w |
|j}|duo5|jS )z^Remove a member from a team.

        Returns:
            Boolean indicating success
        r   	HTTPError)DELETE_INVITE_GQLDeleteInvite)identityFN)requestsr   wandb.apis._generatedr   r   r   executer   r   r   model_validateresultsuccess)r   r   r   r   datar%   r   r   r   delete'   s   zMember.deletec                 C  s   d| j  d| j dS )Nz<Member z (z)>)nameaccount_typer   r   r   r   __repr__;   s   zMember.__repr__)r   r   r   r   r   r   )__name__
__module____qualname____doc__r   r(   r,   __classcell__r   r   r   r   r      s
    r   c                      sb   e Zd ZdZ	d$d% fd	d
Zed$d&ddZd'd(ddZd)ddZd'd*d d!Z	d+d"d#Z
  ZS ),Teama  A class that represents a W&B team.

    This class provides methods to manage W&B teams, including creating teams,
    inviting members, and managing service accounts. It inherits from Attrs
    to handle team attributes.

    Args:
        client (`wandb.apis.public.Api`): The api instance to use
        name (str): The name of the team
        attrs (dict): Optional dictionary of team attributes

    Note:
        Team management requires appropriate permissions.
    Nr   r   r)   r   r   Mapping[str, Any] | Nonec                   s(   t  |pi  || _|| _|   d S r   )r   r   r   r)   load)r   r   r)   r   r   r   r   r   O   s   zTeam.__init__apir
   r   admin_username
str | Nonereturnr   c                 C  sT   ddl m} ddlm} z|jt|||d W n	 |y#   Y nw | |j|S )a'  Create a new team.

        Args:
            api: (`Api`) The api instance to use
            team: (str) The name of the team
            admin_username: (str) optional username of the admin user of the team, defaults to the current user.

        Returns:
            A `Team` object
        r   r   )CREATE_TEAM_GQL)teamNameteamAdminUserName)r!   r   r"   r9   r   r#   r   )clsr5   r   r6   r   r9   r   r   r   createZ   s   zTeam.createFusername_or_emailadminboolc                 C  sd   ddl m} ddlm} d| jd|d|v rdnd|i}z| jt|| W d
S  |y1   Y d	S w )ap  Invite a user to a team.

        Args:
            username_or_email: (str) The username or email address of the user
                you want to invite.
            admin: (bool) Whether to make this user a team admin.
                Defaults to `False`.

        Returns:
            `True` on success, `False` if user was already invited or didn't exist.
        r   r   )CREATE_INVITE_GQLr    r?   @emailusernameFT)r!   r   r"   rA   r)   r   r#   r   )r   r>   r?   r   rA   	variablesr   r   r   invites   s   zTeam.invitedescriptionMember | Nonec                 C  s^   ddl m} ddlm} z| jt|| j|d | d | j	d W S  |y.   Y dS w )zCreate a service account for the team.

        Args:
            description: (str) A description for this service account

        Returns:
            The service account `Member` object, or None on failure
        r   r   )CREATE_SERVICE_ACCOUNT_GQL)r    rG   TN)
r!   r   r"   rI   r   r#   r   r)   r4   members)r   rG   r   rI   r   r   r   create_service_account   s   	

zTeam.create_service_accountforcedict[str, Any]c                   sx   ddl m}m} |s js9 jt|d ji}||}|j	 }r'|
 ni  _ fdd jd D  jd<  jS )zYReturn members that belong to a team.

        <!-- lazydoc-ignore: internal -->
        r   )GET_TEAM_ENTITY_GQLGetTeamEntityr)   c                   s   g | ]
}t  j j|qS r   )r   r   r)   ).0memberr+   r   r   
<listcomp>   s    zTeam.load.<locals>.<listcomp>rK   )r"   rO   rP   _attrsr   r#   r   r)   r$   r    
model_dump)r   rM   rO   rP   r'   r%   r    r   r+   r   r4      s   


z	Team.loadc                 C  s   d| j  dS )Nz<Team >)r)   r+   r   r   r   r,      s   zTeam.__repr__r   )r   r   r)   r   r   r3   )r5   r
   r   r   r6   r7   r8   r   )F)r>   r   r?   r@   r8   r@   )rG   r   r8   rH   )rM   r@   r8   rN   )r8   r   )r-   r.   r/   r0   r   classmethodr=   rF   rL   r4   r,   r1   r   r   r   r   r2   ?   s    
r2   N)r0   
__future__r   collections.abcr   typingr   r   typing_extensionsr   	wandb_gqlr   wandb.apis.attrsr   r5   r
   r   r   r2   r   r   r   r   <module>   s    
&