o
    ÙKÕi<  ã                
   @   s  d dl 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mZmZmZmZ d dlmZmZ d dlmZ G d	d
„ d
eeƒZe jG dd„ de jƒƒZde	dedee deeef fdd„Zdefdd„Zde	defdd„Zeddedd�Zdddeg dddd œZdS )!é    N)ÚOptionalÚTuple)ÚAPIEndpoint)ÚAdditionalInfo)ÚUAConfig)ÚBoolDataValueÚ
DataObjectÚFieldÚIntDataValueÚStringDataValue)Ú!CONTRACT_EXPIRY_GRACE_PERIOD_DAYSÚCONTRACT_EXPIRY_PENDING_DAYS)Úmachine_tokenc                   @   s`   e Zd Zededd�ededdd�ededd�ed	ed
d�gZdede	e
 ded	efdd„ZdS )ÚIsAttachedResultÚis_attachedz=True if the machine is attached to an Ubuntu Pro subscription)ÚdocÚcontract_statusFz%Status of the Ubuntu Pro subscriptionÚcontract_remaining_daysz2Number of days left in the Ubuntu Pro subscriptionÚis_attached_and_contract_validzbTrue if the machine is attached to an Ubuntu Pro subscription and that subscription is not expiredc                C   s   || _ || _|| _|| _d S ©N©r   r   r   r   )Úselfr   r   r   r   © r   úJ/usr/lib/python3/dist-packages/uaclient/api/u/pro/status/is_attached/v1.pyÚ__init__3   s   
zIsAttachedResult.__init__N)Ú__name__Ú
__module__Ú__qualname__r	   r   r   r
   ÚfieldsÚboolr   ÚstrÚintr   r   r   r   r   r      s@    üüýüíýüûúr   c                   @   s    e Zd ZdZdZdZdZdZdS )ÚContractExpiryStatusNÚactivezactive-soon-to-expirezgrace-periodÚexpired)r   r   r   ÚNONEÚACTIVEÚACTIVE_EXPIRED_SOONÚEXPIRED_GRACE_PERIODÚEXPIREDr   r   r   r   r"   A   s    r"   ÚcfgÚis_machine_attachedÚremaining_daysÚreturnc                 C   sŽ   |st jdfS t}t}|du rt j| fS d|  kr|kr&n nt j|fS | |  kr1dk r8n nt j|fS || k rBt j|fS t j|fS )z/Return a tuple [ContractExpiryStatus, num_days]r   N)r"   r%   r   r   r)   r'   r(   r&   )r*   r+   r,   Úgrace_periodÚpending_expiryr   r   r   Ú_get_contract_expiry_statusJ   s   





r0   c                   C   s
   t tƒ ƒS r   )Ú_is_attachedr   r   r   r   r   r   c   s   
r   c                 C   sN   t  | ¡}t|j ƒ}t| ||jƒ\}}d}|r|tjkrd}t||j||d�S )zO
    This endpoint shows if the machine is attached to a Pro subscription.
    TFr   )	r   Úget_machine_token_filer   r0   r   r"   r)   r   Úvalue)r*   Úmachine_token_filer+   r   r,   r   r   r   r   r1   g   s    

ÿÿ
ür1   Úv1Ú
IsAttached)ÚversionÚnameÚfnÚoptions_clsÚ28FzZ
from uaclient.api.u.pro.status.is_attached.v1 import is_attached

result = is_attached()
z#pro api u.pro.status.is_attached.v1zŽ
{
    "contract_remaining_days": 360,
    "contract_status": "active",
    "is_attached": true,
    "is_attached_and_contract_valid": true
}
aò  
.. tab-item:: Explanation
    :sync: explanation

    The ``contract_status`` field can return 4 different states, they are:

    * **active**: The contract is currently valid.
    * **grace-period**: The contract is in the grace period. This means that
      it is expired, but there are still some days where the contract will be
      valid.
    * **active-soon-to-expire**: The contract is almost expired, but still
      valid.
    * **expired**: The contract is expired and no longer valid.
)Úintroduced_inÚrequires_networkÚexample_pythonÚresult_classÚ
exceptionsÚexample_cliÚexample_jsonÚextra) ÚenumÚtypingr   r   Úuaclient.api.apir   Úuaclient.api.data_typesr   Úuaclient.configr   Úuaclient.data_typesr   r   r	   r
   r   Úuaclient.defaultsr   r   Úuaclient.filesr   r   ÚuniqueÚEnumr"   r   r!   r0   r   r1   ÚendpointÚ_docr   r   r   r   Ú<module>   sJ    ,ÿþý

üü
í