
    Jh<              
       J   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
ee      Ze j,                   G d de j.                               Zde	dedee   deeef   fdZdefdZde	defdZ edded      Zdddeg ddddZy)    N)OptionalTuple)APIEndpoint)AdditionalInfo)UAConfig)BoolDataValue
DataObjectFieldIntDataValueStringDataValue)!CONTRACT_EXPIRY_GRACE_PERIOD_DAYSCONTRACT_EXPIRY_PENDING_DAYS)machine_tokenc                       e Zd Z eded       ededd       eded       ed	ed
      gZdede	e
   ded	efdZy)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                <    || _         || _        || _        || _        y Nr   r   r   r   )selfr   r   r   r   s        J/usr/lib/python3/dist-packages/uaclient/api/u/pro/status/is_attached/v1.py__init__zIsAttachedResult.__init__3   s$     '.'>$.L+    N)__name__
__module____qualname__r
   r   r   r   fieldsboolr   strintr    r   r   r   r      s    O		
 	7		
 	%D	

 	,8		
'F:M M "#	M
 "%M )-Mr   r   c                        e Zd ZdZdZdZdZdZy)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    DF1)Gr   r'   cfgis_machine_attachedremaining_daysreturnc                 B   |st         j                  dfS t        }t        }|t         j                  | fS d|cxk  r|k  rn nt         j
                  |fS | |cxk  rdk  rn nt         j                  |fS || k  rt         j                  |fS t         j                  |fS )z/Return a tuple [ContractExpiryStatus, num_days]r   )r'   r*   r   r   r.   r,   r-   r+   )r/   r0   r1   grace_periodpending_expirys        r   _get_contract_expiry_statusr6   J   s     #((!++4L1N #++l]::N,n,#77GG
.	,1	,#88.HH	<-	'#++^;;&&66r   c                  (    t        t                     S r   )_is_attachedr   r%   r   r   r   r   c   s    
##r   c                     t        j                  |       }t        |j                         }t        | ||j                        \  }}d}|r|t
        j                  k(  rd}t        ||j                  ||      S )zO
    This endpoint shows if the machine is attached to a Pro subscription.
    TFr   )	r   get_machine_token_filer"   r6   r   r'   r.   r   value)r/   machine_token_filer0   r   r1   r   s         r   r8   r8   g   s     '==cB1??@&A "4"L"L'#O^ &*"2:::).&''-- .'E	 r   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$   r6   r   r8   endpoint_docr%   r   r   <module>rX      s     " ( 2 $  ))Mz> )MX 499  7	77 SM7 $%	72$% $h #3 4 		 
 %8'!r   