o
    nib                     @   sH   d Z ddlZddlmZ ddlmZ G dd deZG dd deZdS )	zPublic API: teams.    N)gql)Attrsc                       s4   e Zd ZedZ fddZdd Zdd Z  ZS )Memberz
    mutation DeleteInvite($id: String, $entityName: String) {
        deleteInvite(input: {id: $id, entityName: $entityName}) {
            success
        }
    }
  c                    s   t  | || _|| _d S N)super__init___clientteam)selfclientr	   attrs	__class__ U/home/ubuntu/SoloSpeech/.venv/lib/python3.10/site-packages/wandb/apis/public/teams.pyr      s   
zMember.__init__c                 C   s>   z| j | j| j| jdd d W S  tjjy   Y dS w )z^Remove a member from a team.

        Returns:
            Boolean indicating success
        )id
entityNamedeleteInvitesuccessF)r   executeDELETE_MEMBER_MUTATIONr   r	   requests
exceptions	HTTPErrorr
   r   r   r   delete   s   zMember.deletec                 C   s   d| j  d| j dS )Nz<Member z (z)>)nameaccount_typer   r   r   r   __repr__&   s   zMember.__repr__)	__name__
__module____qualname__r   r   r   r   r   __classcell__r   r   r   r   r   	   s    
r   c                       sp   e Zd ZedZedZedZedZd fdd	Ze	ddd	Z
dddZdd ZdddZdd Z  ZS )TeamaN  
    mutation CreateTeam($teamName: String!, $teamAdminUserName: String) {
        createTeam(input: {teamName: $teamName, teamAdminUserName: $teamAdminUserName}) {
            entity {
                id
                name
                available
                photoUrl
                limits
            }
        }
    }
    a  
    mutation CreateInvite($entityName: String!, $email: String, $username: String, $admin: Boolean) {
        createInvite(input: {entityName: $entityName, email: $email, username: $username, admin: $admin}) {
            invite {
                id
                name
                email
                createdAt
                toUser {
                    name
                }
            }
        }
    }
    aT  
    query Entity($name: String!) {
        entity(name: $name) {
            id
            name
            available
            photoUrl
            readOnly
            readOnlyAdmin
            isTeam
            privateOnly
            storageBytes
            codeSavingEnabled
            defaultAccess
            isPaid
            members {
                id
                admin
                pending
                email
                username
                name
                photoUrl
                accountType
                apiKey
            }
        }
    }
    a  
    mutation CreateServiceAccount($entityName: String!, $description: String!) {
        createServiceAccount(
            input: {description: $description, entityName: $entityName}
        ) {
            user {
                id
            }
        }
    }
    Nc                    s(   t  |pi  || _|| _|   d S r   )r   r   r   r   load)r
   r   r   r   r   r   r   r   x   s   zTeam.__init__c                 C   s>   z|j | j||d W n tjjy   Y nw t|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
        )teamNameteamAdminUserName)r   r   CREATE_TEAM_MUTATIONr   r   r   r#   )clsapir	   admin_usernamer   r   r   create~   s   zTeam.createFc                 C   sV   | j |d}d|v r||d< n||d< z| j| j| W dS  tjjy*   Y dS w )aG  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   admin@emailusernameFT)r   r   r   CREATE_INVITE_MUTATIONr   r   r   )r
   username_or_emailr,   	variablesr   r   r   invite   s   

zTeam.invitec                 C   sH   z| j | j|| jd | d | jd W S  tjj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
        )descriptionr   TN)	r   r   CREATE_SERVICE_ACCOUNT_MUTATIONr   r$   membersr   r   r   )r
   r4   r   r   r   create_service_account   s   	

zTeam.create_service_accountc                    sN   |s j s$ j jd ji}|d  _  fdd j d D  j d<  j S )Nr   entityc                    s   g | ]
}t  j j|qS r   )r   r   r   ).0memberr   r   r   
<listcomp>   s    zTeam.load.<locals>.<listcomp>r7   )_attrsr   r   
TEAM_QUERYr   )r
   forceresponser   r   r   r$      s   


z	Team.loadc                 C   s   d| j  dS )Nz<Team >)r   r   r   r   r   r      s   zTeam.__repr__r   )F)r   r    r!   r   r'   r0   r>   r6   r   classmethodr+   r3   r8   r$   r   r"   r   r   r   r   r#   *   s(    


r#   )__doc__r   	wandb_gqlr   wandb.apis.attrsr   r   r#   r   r   r   r   <module>   s    !