
    	P                         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dlmZ ddl
mZ dZd	Zd
 Zd Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Zd Zd Zy)z1Helpers for interacting with the Procurement API.    )absolute_import)division)unicode_literals)
exceptions)apis)
properties cloudcommerceconsumerprocurementv1alpha1c                  >    t        j                  t        t              S N)r   GetMessagesModule&COMMERCE_PROCUREMENT_CONSUMER_API_NAME)COMMERCE_PROCUREMENT_CONSUMER_API_VERSION     7lib/googlecloudsdk/api_lib/commerce_procurement/apis.pyr   r          			 F I
K Kr   c                  >    t        j                  t        t              S r   )r   GetClientInstancer   r   r   r   r   r   r   #   r   r   c                       e Zd ZdZ e       j
                  Z e       j                  Ze	d        Z
e	d        Ze	d        Zy)Accountsz@The Accounts set of Commerce Procurement Consumer API functions.c                  *    t               j                  S r   )r   billingAccounts_accountsr   r   r   
GetServicezAccounts.GetService0   s    777r   c                     t               j                  |       }	 t        j                         j	                  |      S # t
        j                  $ r}t        j                  |      d}~ww xY w)zCalls the Procurement Consumer Accounts.Get method.

    Args:
      account_name: Name of an account.

    Returns:
      (Account)
    nameN)	r   ACloudcommerceconsumerprocurementBillingAccountsAccountsGetRequestr   r   Getapitools_exceptions	HttpErrorr   HttpException)account_namerequesterrors      r   r   zAccounts.Get4   sk       GG H  ,  "&&w//(( ,$$U++,   "? A,A''A,c                     t               j                  | ||      }	 t        j                         j	                  |      S # t
        j                  $ r}t        j                  |      d}~ww xY w)a2  Calls the Procurement Consumer Accounts.List method.

    Args:
      billing_account_name: Name of a billing account.
      page_size: Max size of records to be retrieved in page.
      page_token: Token to specify page in list.

    Returns:
      List of Accounts and next page token if applicable.
    parentpageSize	pageTokenN)	r   BCloudcommerceconsumerprocurementBillingAccountsAccountsListRequestr   r   Listr    r!   r   r"   )billing_account_name	page_size
page_tokenr$   r%   s        r   r-   zAccounts.ListF   sp       HH#i: I O ,  "''00(( ,$$U++,s   "A A.A))A.N)__name__
__module____qualname____doc__r   r   GET_REQUESTr,   LIST_REQUESTstaticmethodr   r   r-   r   r   r   r   r   (   sg    H! EE " FF  8 8 , ," , ,r   r   c                       e Zd ZdZ e       j
                  Z e       j                  Ze	d        Z
e	d        Ze	d        Zy)EntitlementszDThe Entitlements set of Commerce Procurement Consumer API functions.c                  *    t               j                  S r   )r   projects_entitlementsr   r   r   r   zEntitlements.GetServicec   s    444r   c                     t               j                  |       }	 t        j                         j	                  |      S # t
        j                  $ r}t        j                  |      d}~ww xY w)zCalls the Procurement Consumer Entitlements.Get method.

    Args:
      entitlement_name: Name of an entitlement.

    Returns:
      (Entitlement)
    r   N)	r   >CloudcommerceconsumerprocurementProjectsEntitlementsGetRequestr9   r   r   r    r!   r   r"   )entitlement_namer$   r%   s      r   r   zEntitlements.Getg   sk       DD E  ,$$&**733(( ,$$U++,r&   c                 L   dt         j                  j                  j                  j	                         z  }t               j                  || |      }	 t        j                         j                  |      S # t        j                  $ r}t        j                  |      d}~ww xY w)a  Calls the Procurement Consumer Entitlements.List method.

    Args:
      page_size: Max size of records to be retrieved in page.
      page_token: Token to specify page in list.

    Returns:
      List of Entitlements and next page token if applicable.
    projects/%sr(   N)r   VALUEScoreproject	GetOrFailr   ?CloudcommerceconsumerprocurementProjectsEntitlementsListRequestr9   r   r-   r    r!   r   r"   )r/   r0   project_namer$   r%   s        r   r-   zEntitlements.Listy   s     !:#4#4#9#9#A#A#K#K#MML EEi: F G ,$$&++G44(( ,$$U++,s   "A6 6B#	BB#N)r1   r2   r3   r4   r   r=   r5   rE   r6   r7   r   r   r-   r   r   r   r9   r9   [   sg    L! BB " CC  5 5 , ," , ,r   r9   c                       e Zd ZdZ e       j
                  Z e       j                  Ze	d        Z
e	d        Ze	d        Zy)
FreeTrialszCThe Free Trials set of Commerce Procurement Consumer API functions.c                  *    t               j                  S r   )r   projects_freeTrialsr   r   r   r   zFreeTrials.GetService   s    222r   c                    dt         j                  j                  j                  j	                         z  }d| z  }t               j                  ||      }t               j                  ||      }	 t        j                         j                  |      S # t        j                  $ r}t        j                  |      d}~ww xY w)zCalls the Procurement Consumer FreeTrials.Create method.

    Args:
      provider_id: Id of the provider.
      product_external_name: Name of the product.

    Returns:
      (Operation)
    r@   providers/%s)providerproductExternalName)r)   7googleCloudCommerceConsumerProcurementV1alpha1FreeTrialN)r   rA   rB   rC   rD   r   7GoogleCloudCommerceConsumerProcurementV1alpha1FreeTrial?CloudcommerceconsumerprocurementProjectsFreeTrialsCreateRequestrH   r   Creater    r!   r   r"   )provider_idproduct_external_namerF   provider_name
free_trialr$   r%   s          r   rR   zFreeTrials.Create   s     !:#4#4#9#9#A#A#K#K#MML"[0M" ==4I > K    EE@J F L ,""$++G44(( ,$$U++,s   2"B C(B==Cc                 N   dt         j                  j                  j                  j	                         z  }t               j                  || ||      }	 t        j                         j                  |      S # t        j                  $ r}t        j                  |      d}~ww xY w)aH  Calls the Procurement Consumer FreeTrials.List method.

    Args:
      page_size: Max size of records to be retrieved in page.
      page_token: Token to specify page in list.
      filter_rule: The filter that can be used to limit the the result.

    Returns:
      List of Free Trials and next page token if applicable.
    r@   r)   r*   r+   filterN)r   rA   rB   rC   rD   r   =CloudcommerceconsumerprocurementProjectsFreeTrialsListRequestrH   r   r-   r    r!   r   r"   )r/   r0   filter_rulerF   r$   r%   s         r   r-   zFreeTrials.List   s     !:#4#4#9#9#A#A#K#K#MML CC	 D  ,""$))'22(( ,$$U++,s   "A7 7B$
BB$N)r1   r2   r3   r4   r   rQ   CREATE_REQUESTrZ   r6   r7   r   rR   r-   r   r   r   rH   rH      sg    K$ CC " AA  3 3 , ,0 , ,r   rH   c                      e Zd ZdZ e       j
                  Z e       j                  Z e       j                  Z
 e       j                  Z e       j                  Zed        Zed        Zed        Zed        Zed        Zed        Zy)	Ordersz>The Orders set of Commerce Procurement Consumer API functions.c                  *    t               j                  S r   )r   billingAccounts_ordersr   r   r   r   zOrders.GetService   s    555r   c                    t               j                  |      }t               j                  | |      }	 t        j	                         j                  |      S # t        j                  $ r}t        j                  |      d}~ww xY w)zCalls the Procurement Consumer Orders.Cancel method.

    Args:
      order_name: Name of an order.
      etag: Weak etag for validation purpose.

    Returns:
      (Operation)
    )etag)r   @googleCloudCommerceConsumerProcurementV1alpha1CancelOrderRequestN)
r   @GoogleCloudCommerceConsumerProcurementV1alpha1CancelOrderRequestBCloudcommerceconsumerprocurementBillingAccountsOrdersCancelRequestr^   r   Cancelr    r!   r   r"   )
order_namerb   cancel_detail_requestr$   r%   s        r   rf   zOrders.Cancel   s     . FF G     HHI^ I  
, ''00(( ,$$U++,s   "A B-BBc                     t               j                  |       }	 t        j                         j	                  |      S # t
        j                  $ r}t        j                  |      d}~ww xY w)zCalls the Procurement Consumer Orders.Get method.

    Args:
      order_name: Name of an order.

    Returns:
      (Order)
    r   N)	r   ?CloudcommerceconsumerprocurementBillingAccountsOrdersGetRequestr^   r   r   r    r!   r   r"   )rg   r$   r%   s      r   r   z
Orders.Get   sk       EE F  , $$W--(( ,$$U++,r&   c                     t               j                  | |||      }	 t        j                         j	                  |      S # t
        j                  $ r}t        j                  |      d}~ww xY w)av  Calls the Procurement Consumer Orders.List method.

    Args:
      billing_account_name: Name of a billing account.
      page_size: Max size of records to be retrieved in page.
      page_token: Token to specify page in list.
      filter_rule: The filter that can be used to limit the the result.

    Returns:
      List of orders and next page token if applicable.
    rX   N)	r   @CloudcommerceconsumerprocurementBillingAccountsOrdersListRequestr^   r   r-   r    r!   r   r"   )r.   r/   r0   r[   r$   r%   s         r   r-   zOrders.List  st       FF#	 G  , %%g..(( ,$$U++,s   "A A/A**A/c           
      &   |rg }|D ]  }d}d}g }	|j                         D ]-  \  }
}|
dk(  s|
dk(  r|
dk(  r|d   }|
dk(  r|d   }(|j                  dd      }t        |      dk  rt               j	                  |	      }n|d
   dk(  rt               j	                  |d   	      }n{|d
   dk(  r't               j	                  t        |d               }nL|d
   dk(  r't               j	                  t        |d               }nt        dj                  |d
               |	j                  t               j                  |
|             0 |r|rt               j                  |||	      }nd}|j                  t               j                  |d   t        |d         |              t               j                  |t               j                  |            }n=t               j                  |t               j!                  t#        |      |            }t               j%                  | |      }	 t&        j)                         j+                  |      S # t,        j.                  $ r}t1        j2                  |      d}~ww xY w)a  Calls the Procurement Consumer Orders.Cancel method.

    Args:
      order_name: Name of an order.
      etag: Weak etag for validation purpose.
      product_requests: Modification details if order modification is based on
                        product plans.
      quote_change_type: Change type if order modification is based on quote.
      new_quote_external_name: External name of new quote.

    Returns:
      (Operation)
     zline-item-idzline-item-change-typeproduct-external-nameflavor-external-name:      stringValuer   strint
int64ValuedoubledoubleValuezUnrecognized value type {}r   valuerN   flavorExternalName
parametersN)
lineItemId
changeTypenewLineItemInfo)modifications)rb   modifyProductsOrderRequest)r   newQuoteExternalName)rb   modifyQuoteOrderRequest)r   @googleCloudCommerceConsumerProcurementV1alpha1ModifyOrderRequest)itemssplitlenr   <GoogleCloudCommerceConsumerProcurementV1alpha1ParameterValuerw   float
ValueErrorformatappend7GoogleCloudCommerceConsumerProcurementV1alpha1Parameter:GoogleCloudCommerceConsumerProcurementV1alpha1LineItemInfoTGoogleCloudCommerceConsumerProcurementV1alpha1ModifyProductsOrderRequestModificationGetLineItemChangeTypeEnum@GoogleCloudCommerceConsumerProcurementV1alpha1ModifyOrderRequestHGoogleCloudCommerceConsumerProcurementV1alpha1ModifyProductsOrderRequestEGoogleCloudCommerceConsumerProcurementV1alpha1ModifyQuoteOrderRequestGetQuoteChangeTypeEnumBCloudcommerceconsumerprocurementBillingAccountsOrdersModifyRequestr^   r   Modifyr    r!   r   r"   )rg   rb   product_requestsquote_change_typenew_quote_external_namemodificationproduct_requestrT   flavor_external_namer   keyr~   value_splitvalue_argumentnew_line_item_infomodify_detail_requestr$   r%   s                     r   r   zOrders.Modify   s      l-/ "!
+113LS%N"c-D&D++$34K$L!**#23I#J C++!. JJ! K #  1~&. JJ'N K ,  1~&. JJ{1~. K 0  1~). JJ!+a.1 K 3  9@@A  ! ! 

- CCn D ./= 4D !%90  FF"7!5# G %   $
- 

^
^&~60 78:.	 _ 0	1a .n 0 HH%6%8
R
R( S * 	I 	+  0 HH"3"5
O
O/0AB#: P < 	I 	=    HHI^ I  , ''00(( ,$$U++,s    "I# #J6JJc                    d|z  }|rg }|D ]a  }g }	|j                         D ]  \  }
}|
dk(  s|
dk(  r|j                  dd      }t        |      dk  rt               j	                  |      }n|d   d	k(  rt               j	                  |d         }n{|d   d
k(  r't               j	                  t        |d               }nL|d   dk(  r't               j	                  t        |d               }nt        dj                  |d               |	j                  t               j                  |
|              |j                  t               j                  |d   |d   |	             d t               j                  |||t               j                  |            }n5t               j                  |||t               j                  |            }t               j                  | |      }	 t         j#                         j%                  |      S # t&        j(                  $ r}t+        j,                  |      d}~ww xY w)a  Calls the Procurement Consumer Orders.Cancel method.

    Args:
      billing_account_name: Name of parent billing account.
      display_name: Display name of the order.
      provider_id: Id of the provider for which the order is created.
      request_id: Id of the request for idempotency purpose.
      product_requests: Request about product info to place order against.
      quote_external_name: External name of the quote to place order against.

    Returns:
      (Operation)
    rL   ro   rp   rq   rr   rs   rt   r   rv   rw   rx   rz   r{   zUnrecognized value type {}.r}   r   )lineItemInfo)displayNamerM   	requestIdplaceProductsOrderRequest)quoteExternalName)r   rM   r   placeQuoteOrderRequest)r)   ?googleCloudCommerceConsumerProcurementV1alpha1PlaceOrderRequestN)r   r   r   r   r   rw   r   r   r   r   r   r   ?GoogleCloudCommerceConsumerProcurementV1alpha1PlaceOrderRequestGGoogleCloudCommerceConsumerProcurementV1alpha1PlaceProductsOrderRequestDGoogleCloudCommerceConsumerProcurementV1alpha1PlaceQuoteOrderRequestACloudcommerceconsumerprocurementBillingAccountsOrdersPlaceRequestr^   r   Placer    r!   r   r"   )r.   display_namerS   
request_idr   quote_external_namerU   line_item_infor   r   r   r~   r   r   place_detail_requestr$   r%   s                    r   r   zOrders.Place  s     #[0Mn-/
+113LS%++s6L/LC++!. JJ! K #  1~&. JJ'N K ,  1~&. JJ{1~. K 0  1~). JJ!+a.1 K 3  :AAA  ! ! 

- CCn D ./1 48 	/ 

D
D /0G H./EF! E #	$= .H / GG" $5$7
Q
Q) R + 	H 	,  / GG" !2!4OO 3 P 5 	H 	6    GG#H\ H  , &&w//(( ,$$U++,s   9"H I	/II	N)r1   r2   r3   r4   r   re   CANCEL_REQUESTrj   r5   rl   r6   r   MODIFY_REQUESTr   PLACE_REQUESTr7   r   rf   r   r-   r   r   r   r   r   r^   r^      s    F$ FF ! CC " DD $ FF # EE  6 6 , ,. , ," , ,. `, `,D R, R,r   r^   c                   R    e Zd ZdZ e       j
                  Zed        Zed        Z	y)
OperationszBThe Operations set of Commerce Procurement Consumer API functions.c                  *    t               j                  S r   )r   !billingAccounts_orders_operationsr   r   r   GetOrderOperationServicez#Operations.GetOrderOperationService  s    @@@r   c                     t               j                  |       }	 t        j                         j	                  |      S # t
        j                  $ r}t        j                  |      d}~ww xY w)zCalls the Procurement Consumer Orders.Operations.Get method.

    Args:
      operation_name: Name of the order operation.

    Returns:
      Order operation.
    r   N)	r   ICloudcommerceconsumerprocurementBillingAccountsOrdersOperationsGetRequestr   r   r   r    r!   r   r"   )operation_namer$   r%   s      r   GetOrderOperationzOperations.GetOrderOperation  sk       OO P  ,00266w??(( ,$$U++,r&   N)
r1   r2   r3   r4   r   r   GET_ORDER_OPERATION_REQUESTr7   r   r   r   r   r   r   r     sB    J 1 !MM  A A , ,r   r   c                 \   | dk(  r,t               j                         j                  j                  S | dk(  r,t               j                         j                  j                  S | dk(  r,t               j                         j                  j
                  S t        dj                  |             )zConverts raw input to line item change type.

  Args:
    raw_input: Raw input of the line item change type.

  Returns:
    Converted line item change type.
  Raises:
    ValueError: The raw input is not recognized as a valid change type.
  UPDATECANCELREVERT_CANCELLATIONz&Unrecognized line item change type {}.)r   r   ChangeTypeValueValuesEnumLINE_ITEM_CHANGE_TYPE_UPDATELINE_ITEM_CHANGE_TYPE_CANCEL)LINE_ITEM_CHANGE_TYPE_REVERT_CANCELLATIONr   r   	raw_inputs    r   r   r     s     ( ZZ  < <= H ZZ  < <= )) ZZ  I IJ =DDYO
PPr   c                 \   | dk(  r,t               j                         j                  j                  S | dk(  r,t               j                         j                  j                  S | dk(  r,t               j                         j                  j
                  S t        dj                  |             )zConverts raw input to quote change type.

  Args:
    raw_input: Raw input of the quote change type.

  Returns:
    Converted quote change type.
  Raises:
    ValueError: The raw input is not recognized as a valid change type.
  r   r   r   z"Unrecognized quote change type {}.)r   r   r   QUOTE_CHANGE_TYPE_UPDATEQUOTE_CHANGE_TYPE_CANCEL%QUOTE_CHANGE_TYPE_REVERT_CANCELLATIONr   r   r   s    r   r   r     s     ( KK  8 89 H KK  8 89 )) KK  E EF 9@@K
LLr   N)r4   
__future__r   r   r   apitools.base.pyr   r    googlecloudsdk.api_lib.utilr   googlecloudsdk.corer   r   r   r   r   objectr   r9   rH   r^   r   r   r   r   r   r   <module>r      s    8 &  ' > , 2 *)K &,6 )K
K
0,v 0,f0,6 0,f;, ;,|J,V J,Z, ,:Q6Mr   