o
    l>j+                     @   s   d Z ddlmZmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ dZG dd	 d	eZG d
d deZG dd dZG dd dZG dd dZG dd dZdS )zAccount service.    )AnyOptional)Response)BaseService)PyiCloudSessionunderscore_to_camelcase20288408776c                
       s   e Zd ZdZdedededeeef ddf
 fdd	Z	e
ded
 fddZe
ded fddZe
dddZe
dd ZdefddZdefddZ  ZS )AccountServicezThe 'Account' iCloud service.service_rootsessionchina_mainlandparamsreturnNc                    s   t  ||| g | _g | _d | _| j d| _| j d| _| j d| _| j d| _	| j d| _
d|s9dnd | _| j d	| _| jd
t}| j d| d| _| j d| d| _d S )Nz
/setup/webz/device/getDevicesz/family/getFamilyDetailsz/family/getMemberPhotoz/setup/ws/1/storageUsageInfozhttps://gatewayws.icloud.com z.cnz/acsegatewaydsidz/v1/accounts/z/plans/icloud/pricingz/v3/accounts/z2/subscriptions/features/cloud.storage/plan-summary)super__init___devices_family_storager   _acc_endpoint_acc_devices_url_acc_family_details_url_acc_family_member_photo_url_acc_storage_url_gateway_gateway_rootr   getDEFAULT_DSID_gateway_pricing_url_gateway_summary_plan_url)selfr   r   r   r   r   	__class__ N/home/thesage/.local/lib/python3.10/site-packages/pyicloud/services/account.pyr      s&   

zAccountService.__init__AccountDevicec                 C   sF   | j s | jj| j| jd}| }|d D ]
}| j t| q| j S )zReturns current paired devices.r   devices)r   r   r   r   r   jsonappendr'   )r"   reqresponsedevice_infor%   r%   r&   r)   5   s   zAccountService.devicesFamilyMemberc                 C   sV   | j s(| jj| j| jd}| }|dg D ]}| j t|| j| j| j q| j S )zReturns family members.r(   familyMembers)	r   r   r   r   r   r*   r+   r/   r   )r"   r,   r-   member_infor%   r%   r&   familyA   s   	zAccountService.familyAccountStoragec                 C   s2   | j s| jj| j| jd}| }t|| _ | j S )zReturns storage infos.r(   )r   r   postr   r   r*   r3   r"   r,   r-   r%   r%   r&   storageV   s
   
zAccountService.storagec                 C   s    | j j| j| jd}| }|S )zReturns your subscription plan.r(   )r   r   r!   r   r*   r5   r%   r%   r&   summary_plana   s
   zAccountService.summary_planc                 C   s*   dt | j dt | j d| jjj dS )Nz
{devices: z
, family: z, storage: z bytes free})lenr)   r2   r6   usageavailable_storage_in_bytesr"   r%   r%   r&   __str__j   s   zAccountService.__str__c                 C      dt | j d|  dS N<z: >type__name__r;   r%   r%   r&   __repr__p      zAccountService.__repr__)r   r3   )rC   
__module____qualname____doc__strr   booldictr   r   propertylistr)   r2   r6   r7   r<   rD   __classcell__r%   r%   r#   r&   r
      s.    
$

r
   c                   @   s:   e Zd ZdZdefddZdefddZdefdd	Zd
S )r'   zAccount device.keyc                 C   s   | t | S Nr   r"   rO   r%   r%   r&   __getattr__w   s   zAccountDevice.__getattr__r   c                 C      d| j  d| j dS )Nz{model: z, name: })model_display_namenamer;   r%   r%   r&   r<   z      zAccountDevice.__str__c                 C   r=   r>   rA   r;   r%   r%   r&   rD   }   rE   zAccountDevice.__repr__N)rC   rF   rG   rH   rI   rR   r<   rD   r%   r%   r%   r&   r'   t   s
    r'   c                
   @   sv  e Zd ZdZdeeef dedeeef deddf
dd	Ze	de
e fd
dZe	de
e fddZe	de
e fddZe	de
e fddZe	dd Ze	de
e fddZe	de
e fddZe	dd Ze	de
e fddZe	dd Ze	dd Ze	d d! Ze	d"d# Ze	d$d% Ze	d&d' Ze	d(d) Zdefd*d+Zd,d- Zdefd.d/Zdefd0d1ZdS )2r/   zA family member.r1   r   r   acc_family_member_photo_urlr   Nc                 C   s   || _ || _|| _|| _d S rP   )_attrs_session_paramsr   )r"   r1   r   r   rX   r%   r%   r&   r      s   
zFamilyMember.__init__c                 C      | j dS )zGets the last name.lastNamerY   r   r;   r%   r%   r&   	last_name      zFamilyMember.last_namec                 C   r\   )zGets the dsid.r   r^   r;   r%   r%   r&   r      r`   zFamilyMember.dsidc                 C   r\   )zGets the original invitation.originalInvitationEmailr^   r;   r%   r%   r&   original_invitation_email   r`   z&FamilyMember.original_invitation_emailc                 C   r\   )zGets the full name.fullNamer^   r;   r%   r%   r&   	full_name   r`   zFamilyMember.full_namec                 C   r\   )zGets the age classification.ageClassificationr^   r;   r%   r%   r&   age_classification   r`   zFamilyMember.age_classificationc                 C   r\   )z Gets the apple id for purchases.appleIdForPurchasesr^   r;   r%   r%   r&   apple_id_for_purchases   r`   z#FamilyMember.apple_id_for_purchasesc                 C   r\   )zGets the apple id.appleIdr^   r;   r%   r%   r&   apple_id   r`   zFamilyMember.apple_idc                 C   r\   )zGets the family id.familyIdr^   r;   r%   r%   r&   	family_id   r`   zFamilyMember.family_idc                 C   r\   )zGets the first name.	firstNamer^   r;   r%   r%   r&   
first_name   r`   zFamilyMember.first_namec                 C   r\   )zHas parental privileges.hasParentalPrivilegesr^   r;   r%   r%   r&   has_parental_privileges   r`   z$FamilyMember.has_parental_privilegesc                 C   r\   )zHas screen time enabled.hasScreenTimeEnabledr^   r;   r%   r%   r&   has_screen_time_enabled   r`   z$FamilyMember.has_screen_time_enabledc                 C   r\   )zHas to ask for buying.hasAskToBuyEnabledr^   r;   r%   r%   r&   has_ask_to_buy_enabled   r`   z#FamilyMember.has_ask_to_buy_enabledc                 C   r\   )zHas share purshases.hasSharePurchasesEnabledr^   r;   r%   r%   r&   has_share_purchases_enabled   r`   z(FamilyMember.has_share_purchases_enabledc                 C   r\   )z"Has share my location with family.#shareMyLocationEnabledFamilyMembersr^   r;   r%   r%   r&   (share_my_location_enabled_family_members   r`   z5FamilyMember.share_my_location_enabled_family_membersc                 C   r\   )zHas share my location.hasShareMyLocationEnabledr^   r;   r%   r%   r&   has_share_my_location_enabled   r`   z*FamilyMember.has_share_my_location_enabledc                 C   r\   )zGets the dsid for purchases.dsidForPurchasesr^   r;   r%   r%   r&   dsid_for_purchases   r`   zFamilyMember.dsid_for_purchasesc                 C   s.   t | j}|d| ji | jj| j|ddS )zReturns the photo.memberIdT)r   stream)rK   r[   updater   rZ   r   r   )r"   params_photor%   r%   r&   	get_photo   s
   
zFamilyMember.get_photoc                 C   s    | j |r| j | S t| |S rP   )rY   r   getattrrQ   r%   r%   r&   __getitem__   s   

zFamilyMember.__getitem__c                 C   rS   )Nz{name: z, age_classification: rT   )rd   rf   r;   r%   r%   r&   r<      s   zFamilyMember.__str__c                 C   r=   r>   rA   r;   r%   r%   r&   rD      rE   zFamilyMember.__repr__) rC   rF   rG   rH   rK   rI   r   r   r   rL   r   r_   r   rb   rd   rf   rh   rj   rl   rn   rp   rr   rt   rv   rx   rz   r|   r   r   r   r<   rD   r%   r%   r%   r&   r/      sb    











r/   c                   @   sf   e Zd ZdZdddZedd Zedd	 Zed
d Zedd Z	de
fddZde
fddZdS )AccountStorageUsageForMedia8Storage used for a specific media type into the account.r   Nc                 C   s
   || _ d S rP   
usage_data)r"   r   r%   r%   r&   r      s   
z$AccountStorageUsageForMedia.__init__c                 C   
   | j d S )zGets the key.mediaKeyr   r;   r%   r%   r&   rO         
zAccountStorageUsageForMedia.keyc                 C   r   )zGets the label.displayLabelr   r;   r%   r%   r&   label  r   z!AccountStorageUsageForMedia.labelc                 C   r   )zGets the HEX color.displayColorr   r;   r%   r%   r&   color  r   z!AccountStorageUsageForMedia.colorc                 C   r   )zGets the usage in bytes.usageInBytesr   r;   r%   r%   r&   usage_in_bytes  r   z*AccountStorageUsageForMedia.usage_in_bytesc                 C   rS   )Nz{key: z	, usage: z bytes})rO   r   r;   r%   r%   r&   r<     rW   z#AccountStorageUsageForMedia.__str__c                 C   r=   r>   rA   r;   r%   r%   r&   rD     rE   z$AccountStorageUsageForMedia.__repr__r   N)rC   rF   rG   rH   r   rL   rO   r   r   r   rI   r<   rD   r%   r%   r%   r&   r      s    




r   c                   @   s   e Zd ZdZd ddZedd Zedd	 Zed
d Zedd Z	edd Z
edd Zedd Zedd Zedd Zedd Zedd ZdefddZdefddZdS )!AccountStorageUsager   r   Nc                 C   s   || _ || _d S rP   )r   
quota_data)r"   r   r   r%   r%   r&   r     s   
zAccountStorageUsage.__init__c                 C   r   )zGets the comp storage in bytes.compStorageInBytesr   r;   r%   r%   r&   comp_storage_in_bytes  r   z)AccountStorageUsage.comp_storage_in_bytesc                 C   r   )zGets the used storage in bytes.usedStorageInBytesr   r;   r%   r%   r&   used_storage_in_bytes#  r   z)AccountStorageUsage.used_storage_in_bytesc                 C      t | jd | j dS )z!Gets the used storage in percent.d      )roundr   total_storage_in_bytesr;   r%   r%   r&   used_storage_in_percent(  s   z+AccountStorageUsage.used_storage_in_percentc                 C   s   | j | j S )z$Gets the available storage in bytes.)r   r   r;   r%   r%   r&   r:   -  r`   z.AccountStorageUsage.available_storage_in_bytesc                 C   r   )z&Gets the available storage in percent.r   r   )r   r:   r   r;   r%   r%   r&   available_storage_in_percent2  s   z0AccountStorageUsage.available_storage_in_percentc                 C   r   )z Gets the total storage in bytes.totalStorageInBytesr   r;   r%   r%   r&   r   9  r   z*AccountStorageUsage.total_storage_in_bytesc                 C   r   )z#Gets the commerce storage in bytes.commerceStorageInBytesr   r;   r%   r%   r&   commerce_storage_in_bytes>  r   z-AccountStorageUsage.commerce_storage_in_bytesc                 C   r   )zGets the over quota.	overQuotar   r;   r%   r%   r&   
quota_overC  r   zAccountStorageUsage.quota_overc                 C   r   )zGets the max tier quota.haveMaxQuotaTierr   r;   r%   r%   r&   quota_tier_maxH  r   z"AccountStorageUsage.quota_tier_maxc                 C   r   )zGets the almost full quota.zalmost-fullr   r;   r%   r%   r&   quota_almost_fullM  r   z%AccountStorageUsage.quota_almost_fullc                 C   r   )zGets the paid quota.	paidQuotar   r;   r%   r%   r&   
quota_paidR  r   zAccountStorageUsage.quota_paidc                 C   s   | j  d| j dS )Nz
% used of z bytes)r   r   r;   r%   r%   r&   r<   W  s   zAccountStorageUsage.__str__c                 C   r=   r>   rA   r;   r%   r%   r&   rD   Z  rE   zAccountStorageUsage.__repr__r   )rC   rF   rG   rH   r   rL   r   r   r   r:   r   r   r   r   r   r   r   rI   r<   rD   r%   r%   r%   r&   r     s6    











r   c                   @   s6   e Zd ZdZd
ddZdefddZdefdd	ZdS )r3   zStorage of the account.r   Nc                 C   sD   t |d|d| _i | _|dD ]}t|| j|d < qd S )NstorageUsageInfoquotaStatusstorageUsageByMediar   )r   r   r9   usages_by_mediar   )r"   storage_datausage_mediar%   r%   r&   r   a  s   zAccountStorage.__init__c                 C   rS   )Nz{usage: z, usages_by_media: rT   )r9   r   r;   r%   r%   r&   r<   l  rW   zAccountStorage.__str__c                 C   r=   r>   rA   r;   r%   r%   r&   rD   o  rE   zAccountStorage.__repr__r   )rC   rF   rG   rH   r   rI   r<   rD   r%   r%   r%   r&   r3   ^  s
    
r3   N)rH   typingr   r   requestsr   pyicloud.services.baser   pyicloud.sessionr   pyicloud.utilsr   r   r
   rK   r'   r/   r   r   r3   r%   r%   r%   r&   <module>   s    fu!G