
    iK                         S r SSKJrJr  SSKrSSKJrJr  SSKJ	r	  SSK
Jr  SSKJr  SS	KJr   " S
 S\5      r " S S5      r " S S5      r " S S5      r " S S5      rg)a  
IBM Cloud Usage Metering is a platform service that enables service providers to submit
metrics collected for  resource instances provisioned by IBM Cloud users. IBM and
third-party service providers that are delivering  an integrated billing service in IBM
Cloud are required to submit usage for all active service instances every hour.  This is
important because inability to report usage can lead to loss of revenue collection for
IBM,  in turn causing loss of revenue share for the service providers.
    )DictListN)BaseServiceDetailedResponse)Authenticator)"get_authenticator_from_environment)convert_model   )get_sdk_headersc                   v    \ rS rSrSrSrSr\\4S\SS 4S jj5       r	 SS	\
SS4S
 jjrS\S\S   S\4S jrSrg)UsageMeteringV4+   zThe usage_metering V4 service.zhttps://billing.cloud.ibm.comusage_meteringservice_namereturnc                 N    [        U5      nU " U5      nUR                  U5        U$ )zv
Return a new client for the usage_metering service using the specified
       parameters and external configuration.
)r   configure_service)clsr   authenticatorservices       a/home/james-whalen/.local/lib/python3.13/site-packages/ibm_platform_services/usage_metering_v4.pynew_instanceUsageMeteringV4.new_instance1   s+     ;<Hm$!!,/    Nr   c                 B    [         R                  " X R                  US9  g)a7  
Construct a new client for the usage_metering service.

:param Authenticator authenticator: The authenticator specifies the authentication mechanism.
       Get up to date information from https://github.com/IBM/python-sdk-core/blob/master/README.md
       about initializing the authenticator of your choice.
)service_urlr   N)r   __init__DEFAULT_SERVICE_URL)selfr   s     r   r   UsageMeteringV4.__init__?   s     	T/G/GWder   resource_idresource_usageResourceInstanceUsagec                    Uc  [        S5      eUc  [        S5      eU Vs/ s H  n[        U5      PM     nn0 n[        U R                  SSS9nUR	                  U5        [
        R                  " U5      nSUS'   SU;   a   UR	                  UR                  S5      5        SUS	'   S
/nU R                  U5      n	[        [        X5      5      n
SR                  " S0 U
D6nU R                  SXUS9nU R                  U5      nU$ s  snf )a  
Report Resource Controller resource usage.

Report usage for resource instances that were provisioned through the resource
controller.

:param str resource_id: The resource for which the usage is submitted.
:param List[ResourceInstanceUsage] resource_usage:
:param dict headers: A `dict` containing the request headers
:return: A `DetailedResponse` containing the result, headers and HTTP status code.
:rtype: DetailedResponse with `dict` result representing a `ResponseAccepted` object
zresource_id must be providedzresource_usage must be providedV4report_resource_usage)r   service_versionoperation_idzapplication/jsonzcontent-typeheadersAcceptr!   z*/v4/metering/resources/{resource_id}/usagePOST)methodurlr)   data )
ValueErrorr	   r   DEFAULT_SERVICE_NAMEupdatejsondumpsgetencode_path_varsdictzipformatprepare_requestsend)r   r!   r"   kwargsxr)   sdk_headersr.   path_param_keyspath_param_valuespath_param_dictr-   requestresponses                 r   r&   %UsageMeteringV4.report_resource_usageP   s     ;<<!>??4BCNq-*NC%22DWn
 	{#zz.)"4NN6::i01.(/ 11+>s?FG:AATOT&&f#UY&Z99W%+ Ds   Dr/   )N)__name__
__module____qualname____firstlineno____doc__r   r1   classmethodstrr   r   r   r   r   r&   __static_attributes__r/   r   r   r   r   +   s|    (9+ 1 
  (,f$f 
f"))045L0M)	)r   r   c                       \ rS rSrSrS\S\SS4S jr\S\	SS 4S	 j5       r
\S
 5       rS\	4S jrS rS\4S jrSS S\4S jrSS S\4S jrSrg)MeasureAndQuantity   aM  
A usage measurement.

:attr str measure: The name of the measure.
:attr object quantity: For consumption-based submissions, `quantity` can be a
      double or integer value. For event-based submissions that do not have binary
      states, previous and current values are required, such as `{ "previous": 1,
      "current": 2 }`.
measurequantityr   Nc                     Xl         X l        g)ae  
Initialize a MeasureAndQuantity object.

:param str measure: The name of the measure.
:param object quantity: For consumption-based submissions, `quantity` can
       be a double or integer value. For event-based submissions that do not have
       binary states, previous and current values are required, such as `{
       "previous": 1, "current": 2 }`.
NrP   rQ   )r   rP   rQ   s      r   r   MeasureAndQuantity.__init__   s      r   _dictc                     0 nSU;   a  UR                  S5      US'   O[        S5      eSU;   a  UR                  S5      US'   O[        S5      eU " S0 UD6$ )>Initialize a MeasureAndQuantity object from a json dictionary.rP   zBRequired property 'measure' not present in MeasureAndQuantity JSONrQ   zCRequired property 'quantity' not present in MeasureAndQuantity JSONr/   r5   r0   r   rU   argss      r   	from_dictMeasureAndQuantity.from_dict   sb     #ii	2DOcdd$yy4Ddee{T{r   c                 $    U R                  U5      $ )rW   r[   r   rU   s     r   
_from_dictMeasureAndQuantity._from_dict        }}U##r   c                     0 n[        U S5      (       a  U R                  b  U R                  US'   [        U S5      (       a  U R                  b  U R                  US'   U$ )1Return a json dictionary representing this model.rP   rQ   )hasattrrP   rQ   r   rU   s     r   to_dictMeasureAndQuantity.to_dict   sT    4##(@#||E)4$$)B $E*r   c                 "    U R                  5       $ rd   rg   r   s    r   _to_dictMeasureAndQuantity._to_dict       ||~r   c                 H    [         R                  " U R                  5       SS9$ )z9Return a `str` version of this MeasureAndQuantity object.   indentr3   r4   rg   rl   s    r   __str__MeasureAndQuantity.__str__       zz$,,.33r   otherc                 j    [        XR                  5      (       d  gU R                  UR                  :H  $ z=Return `true` when self and other are equal, false otherwise.F
isinstance	__class____dict__r   rx   s     r   __eq__MeasureAndQuantity.__eq__   '    %00}}..r   c                     X:X  + $ zAReturn `true` when self and other are not equal, false otherwise.r/   r   s     r   __ne__MeasureAndQuantity.__ne__         r   rS   )rE   rF   rG   rH   rI   rK   objectr   rJ   r   r[   r`   rg   rm   ru   boolr   r   rL   r/   r   r   rN   rN      s    ! !v !$ ! d ';   $ $ 4 4/0 /T /!0 !T !r   rN   c                       \ rS rSrSrSSS.S\S\S\S\S	\S
   S\S\SS4S jjr\	S\
SS 4S j5       r\	S 5       rS\
4S jrS rS\4S jrSS S\4S jrSS S\4S jrSrg)r#      a;  
Usage information for a resource instance.

:attr str resource_instance_id: The ID of the instance that incurred the usage.
      The ID is a CRN for instances that are provisioned with the resource controller.
:attr str plan_id: The plan with which the instance's usage should be metered.
:attr str region: (optional) The pricing region to which the usage must be
      aggregated. This field is required if the ID is not a CRN or if the CRN does not
      have a region.
:attr int start: The time from which the resource instance was metered in the
      format milliseconds since epoch.
:attr int end: The time until which the resource instance was metered in the
      format milliseconds since epoch. This value is the same as start value for
      event-based submissions.
:attr List[MeasureAndQuantity] measured_usage: Usage measurements for the
      resource instance.
:attr str consumer_id: (optional) If an instance's usage should be aggregated at
      the consumer level, specify the ID of the consumer. Usage is accumulated to the
      instance-consumer combination.
N)regionconsumer_idresource_instance_idplan_idstartendmeasured_usagerN   r   r   r   c                X    Xl         X l        X`l        X0l        X@l        XPl        Xpl        g)aY  
Initialize a ResourceInstanceUsage object.

:param str resource_instance_id: The ID of the instance that incurred the
       usage. The ID is a CRN for instances that are provisioned with the resource
       controller.
:param str plan_id: The plan with which the instance's usage should be
       metered.
:param int start: The time from which the resource instance was metered in
       the format milliseconds since epoch.
:param int end: The time until which the resource instance was metered in
       the format milliseconds since epoch. This value is the same as start value
       for event-based submissions.
:param List[MeasureAndQuantity] measured_usage: Usage measurements for the
       resource instance.
:param str region: (optional) The pricing region to which the usage must be
       aggregated. This field is required if the ID is not a CRN or if the CRN
       does not have a region.
:param str consumer_id: (optional) If an instance's usage should be
       aggregated at the consumer level, specify the ID of the consumer. Usage is
       accumulated to the instance-consumer combination.
N)r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   s           r   r   ResourceInstanceUsage.__init__   s+    B %9!
,&r   rU   c                 L   0 nSU;   a  UR                  S5      US'   O[        S5      eSU;   a  UR                  S5      US'   O[        S5      eSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   O[        S5      eSU;   a  UR                  S5      US'   O[        S	5      eS
U;   a9  UR                  S
5       Vs/ s H  n[        R                  U5      PM     snUS
'   O[        S5      eSU;   a  UR                  S5      US'   U " S0 UD6$ s  snf )AInitialize a ResourceInstanceUsage object from a json dictionary.r   zRRequired property 'resource_instance_id' not present in ResourceInstanceUsage JSONr   zERequired property 'plan_id' not present in ResourceInstanceUsage JSONr   r   zCRequired property 'start' not present in ResourceInstanceUsage JSONr   zARequired property 'end' not present in ResourceInstanceUsage JSONr   zLRequired property 'measured_usage' not present in ResourceInstanceUsage JSONr   r/   )r5   r0   rN   r[   r   rU   rZ   r=   s       r   r[   ResourceInstanceUsage.from_dict  s0    !U*+0995K+LD'(stt#ii	2DOfggu"YYx0DNe!IIg.DMdeeE>))E*DKbccu$OTyyYiOj%kOj!&8&B&B1&EOj%kD!"mnnE!"'))M":D{T{ &ls   D!c                 $    U R                  U5      $ )r   r^   r_   s     r   r`    ResourceInstanceUsage._from_dict%  rb   r   c                    0 n[        U S5      (       a  U R                  b  U R                  US'   [        U S5      (       a  U R                  b  U R                  US'   [        U S5      (       a  U R                  b  U R                  US'   [        U S5      (       a  U R                  b  U R                  US'   [        U S5      (       a  U R
                  b  U R
                  US'   [        U S5      (       a:  U R                  b-  U R                   Vs/ s H  o"R                  5       PM     snUS'   [        U S5      (       a  U R                  b  U R                  US'   U$ s  snf )rd   r   r   r   r   r   r   r   )	re   r   r   r   r   r   r   rg   r   r   rU   r=   s      r   rg   ResourceInstanceUsage.to_dict*  s0   4/00T5N5N5Z,0,E,EE()4##(@#||E)4""t{{'>"kkE(O4!!djj&<!ZZE'N4DHH$888E%L4)**t/B/B/N<@<O<O&P<Oqyy{<O&PE"#4''D,<,<,H#'#3#3E-  'Qs   Ec                 "    U R                  5       $ rj   rk   rl   s    r   rm   ResourceInstanceUsage._to_dict=  ro   r   c                 H    [         R                  " U R                  5       SS9$ )z<Return a `str` version of this ResourceInstanceUsage object.rq   rr   rt   rl   s    r   ru   ResourceInstanceUsage.__str__A  rw   r   rx   c                 j    [        XR                  5      (       d  gU R                  UR                  :H  $ rz   r{   r   s     r   r   ResourceInstanceUsage.__eq__E  r   r   c                     X:X  + $ r   r/   r   s     r   r   ResourceInstanceUsage.__ne__K  r   r   )r   r   r   r   r   r   r   )rE   rF   rG   rH   rI   rK   intr   r   rJ   r   r[   r`   rg   rm   ru   r   r   r   rL   r/   r   r   r#   r#      s    : ''!'' '' 	''
 '' 12'' '' '' 
''R d '>  : $ $ &4 4/3 / /!3 ! !r   r#   c                       \ rS rSrSrSSS.S\S\S\S\S	S4
S
 jjr\S\	S	S 4S j5       r
\S 5       rS	\	4S jrS rS	\4S jrSS S	\4S jrSS S	\4S jrSrg)ResourceUsageDetailsiP  a  
Resource usage details.

:attr int status: A response code similar to HTTP status codes.
:attr str location: The location of the usage.
:attr str code: (optional) The error code that was encountered.
:attr str message: (optional) A description of the error.
N)codemessagestatuslocationr   r   r   c                4    Xl         X l        X0l        X@l        g)a  
Initialize a ResourceUsageDetails object.

:param int status: A response code similar to HTTP status codes.
:param str location: The location of the usage.
:param str code: (optional) The error code that was encountered.
:param str message: (optional) A description of the error.
N)r   r   r   r   )r   r   r   r   r   s        r   r   ResourceUsageDetails.__init__Z  s      	r   rU   c                    0 nSU;   a  UR                  S5      US'   O[        S5      eSU;   a  UR                  S5      US'   O[        S5      eSU;   a  UR                  S5      US'   SU;   a  UR                  S5      US'   U " S0 UD6$ )@Initialize a ResourceUsageDetails object from a json dictionary.r   zCRequired property 'status' not present in ResourceUsageDetails JSONr   zERequired property 'location' not present in ResourceUsageDetails JSONr   r   r/   rX   rY   s      r   r[   ResourceUsageDetails.from_dicth  s     u"YYx0DNdee$yy4DfggU? 99V,DL#ii	2DO{T{r   c                 $    U R                  U5      $ )r   r^   r_   s     r   r`   ResourceUsageDetails._from_dictz  rb   r   c                 r   0 n[        U S5      (       a  U R                  b  U R                  US'   [        U S5      (       a  U R                  b  U R                  US'   [        U S5      (       a  U R                  b  U R                  US'   [        U S5      (       a  U R                  b  U R                  US'   U$ )rd   r   r   r   r   )re   r   r   r   r   rf   s     r   rg   ResourceUsageDetails.to_dict  s    4""t{{'>"kkE(O4$$)B $E*4  TYY%: IIE&M4##(@#||E)r   c                 "    U R                  5       $ rj   rk   rl   s    r   rm   ResourceUsageDetails._to_dict  ro   r   c                 H    [         R                  " U R                  5       SS9$ )z;Return a `str` version of this ResourceUsageDetails object.rq   rr   rt   rl   s    r   ru   ResourceUsageDetails.__str__  rw   r   rx   c                 j    [        XR                  5      (       d  gU R                  UR                  :H  $ rz   r{   r   s     r   r   ResourceUsageDetails.__eq__  r   r   c                     X:X  + $ r   r/   r   s     r   r   ResourceUsageDetails.__ne__  r   r   )r   r   r   r   )rE   rF   rG   rH   rI   r   rK   r   rJ   r   r[   r`   rg   rm   ru   r   r   r   rL   r/   r   r   r   r   P  s     CGW[ s c C QT `d  d '=  " $ $ 4 4/2 /t /!2 !t !r   r   c                       \ rS rSrSrS\S   SS4S jr\S\SS 4S	 j5       r	\S
 5       r
S\4S jrS rS\4S jrSS S\4S jrSS S\4S jrSrg)ResponseAcceptedi  z
Response when usage submitted is accepted.

:attr List[ResourceUsageDetails] resources: Response body that contains the
      status of each submitted usage record.
	resourcesr   r   Nc                     Xl         g)z
Initialize a ResponseAccepted object.

:param List[ResourceUsageDetails] resources: Response body that contains
       the status of each submitted usage record.
Nr   )r   r   s     r   r   ResponseAccepted.__init__  s	     #r   rU   c                     0 nSU;   a9  UR                  S5       Vs/ s H  n[        R                  U5      PM     snUS'   O[        S5      eU " S0 UD6$ s  snf )<Initialize a ResponseAccepted object from a json dictionary.r   zBRequired property 'resources' not present in ResponseAccepted JSONr/   )r5   r   r[   r0   r   s       r   r[   ResponseAccepted.from_dict  s`     %LQIIVaLb cLbq!5!?!?!BLb cDcdd{T{ !ds   Ac                 $    U R                  U5      $ )r   r^   r_   s     r   r`   ResponseAccepted._from_dict  rb   r   c                     0 n[        U S5      (       a:  U R                  b-  U R                   Vs/ s H  o"R                  5       PM     snUS'   U$ s  snf )rd   r   )re   r   rg   r   s      r   rg   ResponseAccepted.to_dict  sI    4%%$..*D7;~~!F~!))+~!FE+ "Gs   Ac                 "    U R                  5       $ rj   rk   rl   s    r   rm   ResponseAccepted._to_dict  ro   r   c                 H    [         R                  " U R                  5       SS9$ )z7Return a `str` version of this ResponseAccepted object.rq   rr   rt   rl   s    r   ru   ResponseAccepted.__str__  rw   r   rx   c                 j    [        XR                  5      (       d  gU R                  UR                  :H  $ rz   r{   r   s     r   r   ResponseAccepted.__eq__  r   r   c                     X:X  + $ r   r/   r   s     r   r   ResponseAccepted.__ne__  r   r   r   )rE   rF   rG   rH   rI   r   r   rJ   r   r[   r`   rg   rm   rK   ru   r   r   r   rL   r/   r   r   r   r     s    #$'="> #4 # d '9   $ $ 4 4/. /4 /!. !4 !r   r   )rI   typingr   r   r3   ibm_cloud_sdk_corer   r   /ibm_cloud_sdk_core.authenticators.authenticatorr   $ibm_cloud_sdk_core.get_authenticatorr   ibm_cloud_sdk_core.utilsr	   commonr   r   rN   r#   r   r   r/   r   r   <module>r      sa   &   < I S 2 #Nk NlD! D!NE! E!PL! L!^7! 7!r   