
    @)                         d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ dZ	dZ
d	Zd
ZeZe
dddedddedddiZefdZefdZefdZefdZefdZ G d d      Zy)zEssential Contacts API.    )absolute_import)division)unicode_literals)
list_pager)apisessentialcontactsv1alpha1v1beta1v1+googleCloudEssentialcontactsV1alpha1Contact+GoogleCloudEssentialcontactsV1alpha1Contact)
param_namemessage_name*googleCloudEssentialcontactsV1beta1Contact*GoogleCloudEssentialcontactsV1beta1Contact%googleCloudEssentialcontactsV1Contact%GoogleCloudEssentialcontactsV1Contactc                 :    t        j                  t        | d      S )NF)api_nameapi_versionno_http)r   GetClientInstanceAPI_NAMEversions    9lib/googlecloudsdk/api_lib/essential_contacts/contacts.pyr   r   .   s    			We
= =    c                 8    t        j                  t        |       S )N)r   r   )r   GetMessagesModuler   r   s    r   GetMessagesr    3   s    			w	GGr   c                 D    t         |    d   }t        t        |       |      S )z>Gets the contact message for the specified version of the API.r   )_CONTACT_TYPES_BY_VERSIONgetattrr    )r   versioned_message_types     r   GetContactMessager%   7   s%    4W=nM	W%'=	>>r   c                     t         |    d   S )Nr   )r"   r   s    r   GetContactParamNamer'   =   s    	"7	+L	99r   c                 ,    t        |       j                  S N)r%   9NotificationCategorySubscriptionsValueListEntryValuesEnumr   s    r   "GetContactNotificationCategoryEnumr+   A   s    	
HHIr   c                   F    e Zd ZdZefdZd Zd Zd Zd Z	d
dZ
	 	 d
d	Zy)ContactsClientz"Client for Essential Contacts API.c                 <   t        |      | _        | j                  j                  | _        | j                  j                  | _        | j                  j                  | _        | j                  j                  | _	        t        |      | _        t        |      | _        y r)   )r   clientMESSAGES_MODULE	_messagesprojects_contacts_projects_servicefolders_contacts_folders_serviceorganizations_contacts_organizations_servicer%   contact_messager'   contact_param_name)selfr   s     r   __init__zContactsClient.__init__I   so    #G,DK[[00DN![[::D KK88D"&++"D"DD,W5D1':Dr   c                    | j                  |||      }d|| j                  |i}|j                  d      r7 | j                  j                  di |}| j
                  j                  |      S |j                  d      r7 | j                  j                  di |}| j                  j                  |      S  | j                  j                  di |}| j                  j                  |      S )a  Creates an Essential Contact.

    Args:
      parent_name: the full id of the resource to create the contact for in the
        form of [projects|folders|organizations]/{resourceId}
      email: the contact's email address.
      notification_categories: the categories of notifications this contact
        should receive.
      language_tag: the contact's preferred language to receive communication
        in.

    Returns:
      The created contact.
    )email!notificationCategorySubscriptionslanguageTagparentfoldersorganizations )r8   r9   
startswithr1   -EssentialcontactsFoldersContactsCreateRequestr5   Create3EssentialcontactsOrganizationsContactsCreateRequestr7   .EssentialcontactsProjectsContactsCreateRequestr3   )r:   parent_namer=   notification_categorieslanguage_tagcontactargs
create_reqs           r   rF   zContactsClient.CreateY   s     ""*A  # "G k4#:#:GDDi(O4>>OO j""))*55o.U4>>UU j((//
;;NNN 
J!!((44r   c                 L   g }|r|j                  d       |r|j                  d       dj                  |      }| j                  ||      }d|d|| j                  |i}|j	                  d      r7 | j
                  j                  d	i |}| j                  j                  |      S |j	                  d      r7 | j
                  j                  d	i |}| j                  j                  |      S  | j
                  j                  d	i |}| j                  j                  |      S )
a  Updates an Essential Contact.

    Args:
      contact_name: the full id of the contact to update in the form of
        [projects|folders|organizations]/{resourceId}/contacts/{contactId}
      notification_categories: the categories of notifications this contact
        should receive, or None if not updating notification categories.
      language_tag: the contact's preferred language to receive communication
        in, or None if not updating language.

    Returns:
      The updated contact.
    #notification_category_subscriptionsrK   ,)r>   r?   name
updateMaskrA   rB   rC   )appendjoinr8   r9   rD   r1   ,EssentialcontactsFoldersContactsPatchRequestr5   Patch2EssentialcontactsOrganizationsContactsPatchRequestr7   -EssentialcontactsProjectsContactsPatchRequestr3   )	r:   contact_namerJ   rK   update_masksupdate_maskrL   rM   
update_reqs	            r   UpdatezContactsClient.Update{   s0    L?@.)((<(K""*A  # "G 	kD y)N4>>NN j""((44/T4>>TT j((..z::MMM 
J!!''
33r   c                    |j                  d      r7| j                  j                  |      }| j                  j	                  |      S |j                  d      r7| j                  j                  |      }| j                  j	                  |      S | j                  j                  |      }| j                  j	                  |      S )zDeletes an Essential Contact.

    Args:
      contact_name: the full id of the contact to delete in the form of
        [projects|folders|organizations]/{resourceId}/contacts/{contactId}

    Returns:
      Empty response message.
    rA   rR   rB   )	rD   r1   -EssentialcontactsFoldersContactsDeleteRequestr5   Delete3EssentialcontactsOrganizationsContactsDeleteRequestr7   .EssentialcontactsProjectsContactsDeleteRequestr3   )r:   rZ   
delete_reqs      r   rb   zContactsClient.Delete   s     y)>>OO P j""))*55/>>UU V j((//
;;NN O J!!((44r   c                    |j                  d      r7| j                  j                  |      }| j                  j	                  |      S |j                  d      r7| j                  j                  |      }| j                  j	                  |      S | j                  j                  |      }| j                  j	                  |      S )zDescribes an Essential Contact.

    Args:
      contact_name: the full id of the contact to describe in the form of
        [projects|folders|organizations]/{resourceId}/contacts/{contactId}

    Returns:
      The requested contact.
    rA   r`   rB   )	rD   r1   *EssentialcontactsFoldersContactsGetRequestr5   Get0EssentialcontactsOrganizationsContactsGetRequestr7   +EssentialcontactsProjectsContactsGetRequestr3   )r:   rZ   describe_reqs      r   DescribezContactsClient.Describe   s     y)^^NN O l""&&|44/^^TT U l((,,\::>>MM N L!!%%l33r   Nc                 x   d}d}|j                  d      r)| j                  }| j                  j                  |      }nb|j                  d      r)| j                  }| j                  j                  |      }n(| j                  }| j                  j                  |      }t        j                  ||||dd      S )a  Lists Essential Contacts set directly on a Cloud resource.

    Args:
      parent_name: the full name of the parent resource to list contacts for in
        the form of [projects|folders|organizations]/{resourceId}
      page_size: the number of contacts to return per page of the result list.
      limit: the total number of contacts to return.

    Returns:
      The contacts that have been set directly on the requested resource.
    NrA   )r@   rB   contactspageSize)
batch_sizelimitfieldbatch_size_attribute)
rD   r5   r1   +EssentialcontactsFoldersContactsListRequestr7   1EssentialcontactsOrganizationsContactsListRequestr3   ,EssentialcontactsProjectsContactsListRequestr   YieldFromList)r:   rI   	page_sizerq   servicelist_reqs         r   ListzContactsClient.List   s     GHi(%%gKK L h				0++gQQ R h &&gLL M h ##') )r   c           	         d}d}|j                  d      r*| j                  }| j                  j                  ||      }nd|j                  d      r*| j                  }| j                  j                  ||      }n)| j                  }| j                  j                  ||      }t        j                  ||||ddd      S )	a)  Computes the Essential Contacts for a Cloud resource.

    Args:
      parent_name: the full name of the parent resource to compute contacts for
        in the form of [projects|folders|organizations]/{resourceId}
      notification_categories: the notification categories (as choices) to
        retrieve subscribed contacts for.
      page_size: the number of contacts to return per page of the result list.
      limit: the total number of contacts to return.

    Returns:
      The contacts that have been computed from the resource hierarchy.
    NrA   )r@   notificationCategoriesrB   Computern   ro   )rp   rq   methodrr   rs   )
rD   r5   r1   .EssentialcontactsFoldersContactsComputeRequestr7   4EssentialcontactsOrganizationsContactsComputeRequestr3   /EssentialcontactsProjectsContactsComputeRequestr   rw   )r:   rI   rJ   rx   rq   ry   compute_reqs          r   r~   zContactsClient.Compute   s    $ GKi(%%gNNQQ5L R Nk				0++gNNWW5L X Nk &&gNNRR5L S Nk ##') )r   )2   N)__name__
__module____qualname____doc__DEFAULT_API_VERSIONr;   rF   r^   rb   rl   r{   r~   rC   r   r   r-   r-   F   s6    *0 ;  5D)4V5040")N 	))r   r-   N)r   
__future__r   r   r   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   ALPHA_API_VERSIONBETA_API_VERSIONGA_API_VERSIONr   r"   r   r    r%   r'   r+   r-   rC   r   r   <module>r      s     &  ' ' ,  $  CE BD =?   2 =
 , H 2 ? !4 : 0C I
]) ])r   