o
    ÙKÕi%  ã                   @   sø   d dl Z d dlm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 e  e e¡¡ZG dd	„ d	eƒZG d
d„ deƒZG dd„ deƒZG dd„ dee	ƒ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dddœZdS )é    N)ÚList)ÚentitlementsÚutil)ÚAPIEndpoint)ÚAdditionalInfo)ÚUAConfig)Ú
DataObjectÚFieldÚStringDataValueÚ	data_listc                   @   s:   e Zd Zededd�ededd�gZdedefdd„ZdS )	ÚReasonÚcodez'Short string that represents the reason©ÚdocÚtitlez9Longer string describing the reason - possibly translatedc                C   ó   || _ || _d S ©N©r   r   )Úselfr   r   © r   úM/usr/lib/python3/dist-packages/uaclient/api/u/pro/services/dependencies/v1.pyÚ__init__   ó   
zReason.__init__N)Ú__name__Ú
__module__Ú__qualname__r	   r
   ÚfieldsÚstrr   r   r   r   r   r      ó    ýýúr   c                   @   s:   e Zd Zededd�ededd�gZdedefdd„ZdS )	ÚServiceWithReasonÚnameú0Name of the Pro service this item corresponds tor   Úreasonz0Reason that this service is in the list it is inc                C   r   r   ©r    r"   )r   r    r"   r   r   r   r   .   r   zServiceWithReason.__init__N)	r   r   r   r	   r
   r   r   r   r   r   r   r   r   r       r   r   c                   @   sZ   e Zd Zededd�edeeƒdd�edeeƒdd�gZdede	e de	e fdd	„Z
d
S )ÚServiceWithDependenciesr    r!   r   Úincompatible_withzkList of Pro services this service is incompatible with. That means they cannot be enabled at the same time.Ú
depends_onzwList of Pro services this service depends on. The services in this list must be enabled for this service to be enabled.c                C   s   || _ || _|| _d S r   ©r    r%   r&   )r   r    r%   r&   r   r   r   r   L   s   
z ServiceWithDependencies.__init__N)r   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r$   3   s0    ýüüòýüûr$   c                   @   s2   e Zd Zedeeƒdd�gZdee fdd„ZdS )ÚDependenciesResultÚservicesz*Each Pro service gets an item in this listr   c                C   s
   || _ d S r   ©r)   )r   r)   r   r   r   r   a   ó   
zDependenciesResult.__init__N)	r   r   r   r	   r   r$   r   r   r   r   r   r   r   r(   X   s    ýÿr(   Úreturnc                   C   s
   t tƒ ƒS r   )Ú_dependenciesr   r   r   r   r   Údependenciese   r+   r.   Úcfgc              
   C   s¤   g }t jD ]G}|| ƒ}g }g }|jD ]}| t|jjt|jj|jj	d�d�¡ q|j
D ]}| t|jjt|jj|jj	d�d�¡ q+| t|j||d�¡ qt|d�S )a  
    This endpoint will return a full list of all service dependencies,
    regardless of the current system state. That means it will always return
    the same thing until new services are added, or until we add/remove
    dependencies between services.
    r   r#   r'   r*   )r   ÚENTITLEMENT_CLASSESÚincompatible_servicesÚappendr   Úentitlementr    r   Ú	named_msgÚmsgÚrequired_servicesr$   r(   )r/   r)   Úent_clsÚentr%   r&   Úent_with_reasonr   r   r   r-   i   sB   

þþÿ
	þþÿ	ýÿ
r-   Úv1ÚServiceDependencies)Úversionr    ÚfnÚoptions_clsÚ32Fz^
from uaclient.api.u.pro.services.dependencies.v1 import dependencies
result = dependencies()
z&pro api u.pro.services.dependencies.v1aË  
{
    "services": [
        {
            "name": "one",
            "depends_on": [
                {
                    "name": "zero",
                    "reason": {
                        "code": "one-and-zero",
                        "title": "Service One requires service Zero."
                    }
                },
                ...
            ],
            "incompatible_with": [
                {
                    "name": "two",
                    "reason": {
                        "code": "one-and-two",
                        "title": "Services One and Two are not compatible."
                    }
                },
                ...
            ]
        },
        ...
    ]
}
)Úintroduced_inÚrequires_networkÚexample_pythonÚresult_classÚexample_cliÚexample_json)ÚloggingÚtypingr   Úuaclientr   r   Úuaclient.api.apir   Úuaclient.api.data_typesr   Úuaclient.configr   Úuaclient.data_typesr   r	   r
   r   Ú	getLoggerÚreplace_top_level_logger_namer   ÚLOGr   r   r$   r(   r.   r-   ÚendpointÚ_docr   r   r   r   Ú<module>   s6    %*ü
÷