
    '                        S r SSKrSSKJr  SSKJr  SSKJr  SSKJ	r
  SSKJr  SSKJr  SS	KJr  SSKrS
 rS rS rS rS rS rS rS rS rS rS rS rS rS rS+S jrS r S r!S r"S r#S r$S r%S r&S  r' " S! S"\RP                  5      r)S# r* " S$ S%\RP                  5      r+S& r, " S' S(\RP                  5      r-S) r.S* r/g),z"hooks for billing budgets surface.    N)extra_types)apis)messages)base)
exceptions)yaml)timesc                 B    [         R                  " S[        U 5      5      $ Nbillingbudgets)r   GetMessagesModuleGetApiVersionargss    6lib/googlecloudsdk/command_lib/billingbudgets/hooks.pyr   r      s    			 0-2E	FF    c                 0    [         R                  " SU 5      $ r   )r   r   )versions    r   GetMessagesModuleForVersionr   #   s    			 0'	::r   c                     [        U S5      (       a7  U R                  R                  5       [        R                  R                  :X  a  gg)Ncalliope_commandv1v1beta1)hasattrr   ReleaseTrackcalliope_baseGAr   s    r   r   r   '   s=    T%&&4+@+@+M+M ,!!$$,%r   c                 h    [        U 5      nUS:X  a  UR                  $ UR                  R                  $ Nr   )r   !googleCloudBillingBudgetsV1Budget3googleCloudBillingBudgetsV1beta1CreateBudgetRequestbudgetr   reqr   s      r   GetVersionedCreateBillingBudgetr%   /   1    $'_000BBIIIr   c                 h    [        U 5      nUS:X  a  UR                  $ UR                  R                  $ r   )r   r    3googleCloudBillingBudgetsV1beta1UpdateBudgetRequestr"   r#   s      r   GetVersionedUpdateBillingBudgetr)   7   r&   r   c                 .    [        S5      n[        X5      $ )z:Convert the input to Money Type for v1beta1 Create method.r   r   
ParseMoneymoneyr   s     r   CreateParseToMoneyTypeV1Beta1r/   ?       (3(	E	$$r   c                 .    [        S5      n[        X5      $ )z5Convert the input to Money Type for v1 Create method.r   r+   r-   s     r   CreateParseToMoneyTypeV1r2   E       (.(	E	$$r   c                 .    [        S5      n[        X5      $ )z:Convert the input to Money Type for v1beta1 Update method.r   r+   r-   s     r   UpdateParseToMoneyTypeV1Beta1r5   K   r0   r   c                 .    [        S5      n[        X5      $ )z5Convert the input to Money Type for v1 Update method.r   r+   r-   s     r   UpdateParseToMoneyTypeV1r7   Q   r3   r   c                 .    [        S5      n[        X5      $ )z9Convert the input to Date Type for v1beta1 Create method.r   r   	ParseDatedater   s     r   CreateParseToDateTypeV1Beta1r=   W       (3(	4	""r   c                 .    [        S5      n[        X5      $ )z4Convert the input to Date Type for v1 Create method.r   r9   r;   s     r   CreateParseToDateTypeV1r@   ]       (.(	4	""r   c                 .    [        S5      n[        X5      $ )z9Convert the input to Date Type for v1beta1 Update method.r   r9   r;   s     r   UpdateParseToDateTypeV1Beta1rC   c   r>   r   c                 .    [        S5      n[        X5      $ )z4Convert the input to Date Type for v1 Update method.r   r9   r;   s     r   UpdateParseToDateTypeV1rE   i   rA   r   c                 j   [        U 5        Sn[        R                  " SU SS 5      (       a  U SS nU(       a  [        R                  " SU SS S5      O[        R                  " SU 5      nUS   (       a  [	        US   5      OSn[        U5      S:  a  [	        US   5      nOSnUR                  XEUS9$ )	z)Validate input and convert to Money Type. z[A-Za-z]{3}Nz\.   r   )unitsnanoscurrencyCode)CheckMoneyRegexrematchsplitintlenGoogleTypeMoney)r.   r   currency_codemoney_arrayrJ   rK   s         r   r,   r,   o   s    %-XXneBCj))"#JM(5bhhueCRj!$288
<  "-Q#k!n
Q%AEE		!	!] 
" 
< <r   c                     [         R                  " XS9nUR                  UR                  UR                  UR
                  S9$ )zConvert to Date Type.)fmt)yearmonthday)r	   ParseDateTimeGoogleTypeDaterX   rY   rZ   )r<   r   rW   datetime_objs       r   r:   r:      sE    $$T3,		 	 L$6$6L<L<L 
! 
N Nr   c                    [        U5      n[        U5      n[        R                  " SU5      nUR                  nUR
                  nU" [        R                  " U R                  5       5      S9nUR                  U5      R                  n	UR                  S5      (       a  / n	U	[        UU5      l
        UR                  S5      (       a)  UR                  n
[        X5      nU[        X5      l
        U$ UR                  S5      (       a  [        R                   " UR"                  5      nUS:X  aC  [$        R&                  " SU0UR(                  5      nUR*                  =R,                  S-  sl        O#[$        R&                  " SU0UR.                  5      nUR0                  =R,                  S-  sl        UR                  [        UU5      l
        U$ )	zAdd threshold rule to budget.r   )nameclear_threshold_rulesadd_threshold_rulethreshold_rules_from_filer   thresholdRulesz,thresholdRules)r   r   r   GetClientInstancebillingAccounts_budgets.BillingbudgetsBillingAccountsBudgetsGetRequestsix	text_typeRelativeNameGetrc   IsSpecifiedr)   ra   AddRulesr   loadrb   messages_utilDictToMessageWithErrorCheck!GoogleCloudBillingBudgetsV1Budgetr    
updateMask&GoogleCloudBillingBudgetsV1beta1Budgetr(   )refr   r$   r   r   clientbudgetsget_request_typeget_requestold_threshold_rulesadded_threshold_rulesfinal_rulesrules_from_filer"   s                 r   UpdateThresholdRulesr|      s   t$($'!!"2G<&**'LL cmmC4D4D4F&GH+K0??	-..:M $D$'))7	*++ 33.FK@K#D.=J	122ii > >?O$88_
-

4
46f 
++66:KK688_
-

9
9;f ;;FFJ[[F ;A:O:O $D$'))7	*r   c                 L    U nU H  nX0;  d  M
  UR                  U5        M     U$ )N)append)	old_rulesrules_to_addall_threshold_rulesrules       r   rl   rl      s.    !d  &  
r   c                 J    [        S5      R                  nU (       a  U" 5       $ g )Nr   )r   0GoogleCloudBillingBudgetsV1beta1LastPeriodAmountuse_last_period_amountr   s     r   LastPeriodAmountV1Beta1r      s(    (AA : r   c                 J    [        S5      R                  nU (       a  U" 5       $ g r   )r   +GoogleCloudBillingBudgetsV1LastPeriodAmountr   s     r   LastPeriodAmountV1r      s(    (
77 : r   c                 ~    A UR                  S5      (       a%  SUR                  R                  R                  l        U$ Nall_updates_rule_pubsub_topic1.0)rk   r!   r"   allUpdatesRuleschemaVersionrs   r   r$   s      r   CreateAllUpdatesRuler      6    		566bgC;;BBQQ_	*r   c                 j    A UR                  S5      (       a  SUR                  R                  l        U$ Nnotifications_rule_pubsub_topicr   rk   r    notificationsRuler   r   s      r   CreateNotificationsRuler      0    		788LQC));;I	*r   c                 ~    A UR                  S5      (       a%  SUR                  R                  R                  l        U$ r   )rk   r(   r"   r   r   r   s      r   UpdateAllUpdatesRuler      r   r   c                 j    A UR                  S5      (       a  SUR                  R                  l        U$ r   r   r   s      r   UpdateNotificationsRuler      r   r   c                       \ rS rSrSrSrg)InvalidBudgetCreditTreatment   zEError to raise when credit treatment doesn't match the credit filter. N__name__
__module____qualname____firstlineno____doc____static_attributes__r   r   r   r   r      s    Mr   r   c                     UR                  S5      =(       a    UR                  S:H  nUR                  S5      =(       a    UR                  nU(       a  U(       d  [        S5      eU(       d  U(       a  [        S5      eU$ )z:Validates credit treatment matches credit types in filter.credit_types_treatmentzinclude-specified-creditsfilter_credit_typesz^'--filter-credit-types' is required when '--credit-types-treatment=include-specified-credits'.zg'--credit-types-treatment' must be 'include-specified-credits' if '--filter-credit-types' is specified.)rk   r   r   r   )
unused_refr   r$   budget_tracks_creditspopulated_credits_filters        r   ValidateCreditTreatmentr      s    **+CD B
!!%@@ !-- :!%!9!9 #;
&	@A A 
#;
&	01 1 
*r   c                       \ rS rSrSrSrg)InvalidBudgetAmountInput   z4Error to raise when user input does not match regex.r   Nr   r   r   r   r   r      s    <r   r   c                 |    [         R                  " S5      n[         R                  " X5      (       d  [        S5      eg )Nz^[0-9]*.?[0-9]+([a-zA-Z]{3})?$zoThe input is not valid for --budget-amount. It must be an int or float with an optional 3-letter currency code.)rN   compilerO   r   )input_stringaccepted_regexs     r   rM   rM      s:    ::?@.	.	/	/
"	NO O 
0r   c                       \ rS rSrSrSrg)InvalidLabelInputi  z2Error to raise when user label input is not valid.r   Nr   r   r   r   r   r     s    :r   r   c                     A UR                  S5      (       aI  [        U5      n[        X5      nUR                  U/S9[	        UU5      R
                  R                  l        U$ )z!Adds labels to an Update request.filter_labels)additionalProperties)rk   r   CreateLabelsLabelsValuer)   budgetFilterlabelsr   )rs   r   r$   r   additional_propertys        r   UpdateParseLabelsr     si    		o&& &H&t6 9A8L8L"5!6 9M 98 $\&&!5	*r   c                 N   [         R                  " U R                  5      n[        U5      S:  a  [	        S5      e[        UR                  5       5      S   n[        X#   5      S:  a  [	        S5      eX#   S   nUR                  R                  U[        R                  " US9/S9$ )z"Parses and validates labels input.rI   zLThe input is not valid for `--filter-labels`. It must be one key/value pair.r   zPThe input is not valid for `--filter-labels`. It must be one key with one value.)string_value)keyvalue)r   rm   r   rR   r   listkeysr   AdditionalPropertyr   	JsonValue)r   r   labels_dictr   r   s        r   r   r     s    		$,,-+
 = > >[ ##	Q
 A B B

1
%				0	0
k++?@ 
1 
B Br   )z%Y-%m-%d)0r   rN   apitools.base.pyr   googlecloudsdk.api_lib.utilr   r   rn   googlecloudsdk.callioper   r   googlecloudsdk.corer   r   googlecloudsdk.core.utilr	   rg   r   r   r   r%   r)   r/   r2   r5   r7   r=   r@   rC   rE   r,   r:   r|   rl   r   r   r   r   r   r   Errorr   r   r   rM   r   r   r   r   r   r   <module>r      s    ) 
 ( , A 9 * $ * 
G;JJ%%%%####<$N(V:#3#3 
"z// 
O
(( 

Br   