
                            d Z ddlmZmZmZ ddlmZ ddlmZ ddlm	Z	 dej                  de	j                  j                  dee   d	ee   fd
Zdej                  de	j                  j                   defdZ	 	 	 	 	 	 ddej                  de	j                  j                   dee   dee   deeeef      deee      dee   dee   fdZ	 ddej                  de	j                  j                   defdZy)z&The BigQuery CLI model client library.    )DictListOptional)	discovery)bq_error)bq_id_utilsmodel_client	referencemax_results
page_tokenc                     | j                         j                  |j                  |j                  ||      j	                         S )a  Lists models for the given dataset reference.

  Arguments:
    model_client: The apiclient used to make the request.
    reference: Reference to the dataset.
    max_results: Number of results to return.
    page_token: Token to retrieve the next page of results.

  Returns:
    A dict that contains entries:
      'results': a list of models
      'token': nextPageToken for the last page, if present.
  )	projectId	datasetId
maxResults	pageToken)modelslistr   r   execute)r	   r
   r   r   s       #platform/bq/clients/client_model.pylist_modelsr      sE    ( t'''' 	   wy	    returnc                 2   t        j                  |t         j                  j                  d       	 | j	                         j                  |j                  |j                  |j                        j                         S # t        j                  $ r Y yw xY w)z!Returns true if the model exists.model_existsmethodr   r   modelIdF)r   	typecheckApiClientHelperModelReferencer   getr   r   r   r   r   BigqueryNotFoundError)r	   r
   s     r   r   r   +   s    
 !!00
	))))%% 
 


 
 
	'	' s   AB   BBNdescription
expirationlabels_to_setlabel_keys_to_removevertex_ai_model_idetagc                    t        j                  |t         j                  j                  d       i }|||d<   |	|xs d|d<   d|vri |d<   |r |j	                         D ]  \  }	}
|
|d   |	<    |r|D ]
  }	d|d   |	<    |d|ig|d<   | j                         j                  ||j                  |j                  |j                  	      }|r|r|n|d
   |j                  d<   |j                          y)a  Updates a Model.

  Args:
    model_client: The apiclient used to make the request.
    reference: the ModelReference to update.
    description: an optional description for model.
    expiration: optional expiration time in milliseconds since the epoch.
      Specifying 0 clears the expiration time for the model.
    labels_to_set: an optional dict of labels to set on this model.
    label_keys_to_remove: an optional list of label keys to remove from this
      model.
    vertex_ai_model_id: an optional string as Vertex AI model ID to register.
    etag: if set, checks that etag in the existing model matches.

  Raises:
    BigqueryTypeError: if reference is not a ModelReference.
  update_modelr   Nr$   expirationTimelabelsr(   trainingRuns)bodyr   r   r   r)   zIf-Match)r   r   r    r!   itemsr   patchr   r   r   headersr   )r	   r
   r$   r%   r&   r'   r(   r)   updated_model	label_keylabel_valuerequests               r   r+   r+   C   s'   6 !!00 -#.M- &0&8DM"#]" M("/"5"5"7	;+6mHi( #8)	+/mHi( *#&:<N%O$PM.!!''####	 ( ' 
*.$M&4IGOOJ	//r   ignore_not_foundc                 :   t        j                  |t         j                  j                  d       	 | j	                         j                  |j                  |j                  |j                        j                          y# t        j                  $ r |s Y yw xY w)a}  Deletes ModelReference reference.

  Args:
    model_client: The apiclient used to make the request.
    reference: the ModelReference to delete.
    ignore_not_found: Whether to ignore "not found" errors.

  Raises:
    BigqueryTypeError: if reference is not a ModelReference.
    bq_error.BigqueryNotFoundError: if reference does not exist and
      ignore_not_found is False.
  delete_modelr   r   N)r   r   r    r!   r   deleter   r   r   r   r   r#   )r	   r
   r7   s      r   r9   r9      s    " !!00
  %%%%!! !  gi		'	'  s   AB BB)NNNNNN)F)__doc__typingr   r   r   googleapiclientr   utilsr   r   Resourcer    DatasetReferenceintstrr   r!   boolr   r+   r9    r   r   <module>rE      s_   , ' ' %  $$**;; # 	>$$**99 
6 "& $.204(,>$$>**99> #> 	>
 DcN+> #49-> !> 3->H #$$**99 r   