2020-06-14 21:09:50 +09:00
|
|
|
|
from typing import List, TYPE_CHECKING, Optional
|
|
|
|
|
|
|
|
|
|
from yandex_music import YandexMusicObject
|
2021-09-19 22:47:19 +09:00
|
|
|
|
from yandex_music.utils import model
|
2020-06-14 21:09:50 +09:00
|
|
|
|
|
|
|
|
|
if TYPE_CHECKING:
|
|
|
|
|
from yandex_music import Client, Deactivation
|
|
|
|
|
|
|
|
|
|
|
2021-09-19 22:47:19 +09:00
|
|
|
|
@model
|
2020-06-14 21:09:50 +09:00
|
|
|
|
class Operator(YandexMusicObject):
|
|
|
|
|
"""Класс, представляющий услугу сотового оператора.
|
|
|
|
|
|
|
|
|
|
Attributes:
|
|
|
|
|
product_id (:obj:`str`): Уникальный идентификатор продукта сервиса Яндекс.Музыка.
|
|
|
|
|
phone (:obj:`str`): Мобильный номер, на который подключена услуга.
|
|
|
|
|
payment_regularity (:obj:`str`): Регулярность оплаты.
|
|
|
|
|
deactivation (:obj:`list` из :obj:`yandex_music.Deactivation`): Способы деактивации.
|
|
|
|
|
title (:obj:`str`): Название услуги.
|
|
|
|
|
suspended (:obj:`bool`): Приостановлено.
|
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
|
|
|
|
"""
|
|
|
|
|
|
2021-09-19 22:47:19 +09:00
|
|
|
|
product_id: str
|
|
|
|
|
phone: str
|
|
|
|
|
payment_regularity: str
|
|
|
|
|
deactivation: List['Deactivation']
|
|
|
|
|
title: str
|
|
|
|
|
suspended: bool
|
|
|
|
|
client: Optional['Client'] = None
|
2020-06-14 21:09:50 +09:00
|
|
|
|
|
2021-09-19 22:47:19 +09:00
|
|
|
|
def __post_init__(self):
|
2020-06-14 21:09:50 +09:00
|
|
|
|
self._id_attrs = (self.product_id, self.phone)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def de_json(cls, data: dict, client: 'Client') -> Optional['Operator']:
|
|
|
|
|
"""Десериализация объекта.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
data (:obj:`dict`): Поля и значения десериализуемого объекта.
|
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
:obj:`yandex_music.Operator`: Услуга сотового оператора.
|
|
|
|
|
"""
|
|
|
|
|
if not data:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
from yandex_music import Deactivation
|
2021-02-03 21:28:10 +09:00
|
|
|
|
|
2020-06-14 21:09:50 +09:00
|
|
|
|
data['deactivation'] = Deactivation.de_list(data.get('deactivation'), client)
|
|
|
|
|
|
|
|
|
|
data = super(Operator, cls).de_json(data, client)
|
|
|
|
|
|
|
|
|
|
return cls(client=client, **data)
|
|
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
|
def de_list(cls, data: dict, client: 'Client') -> List['Operator']:
|
|
|
|
|
"""Десериализация списка объектов.
|
|
|
|
|
|
|
|
|
|
Args:
|
|
|
|
|
data (:obj:`list`): Список словарей с полями и значениями десериализуемого объекта.
|
|
|
|
|
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
|
|
|
|
|
|
|
|
|
Returns:
|
|
|
|
|
:obj:`list` из :obj:`yandex_music.Operator`: Услуги сотового оператора.
|
|
|
|
|
"""
|
|
|
|
|
if not data:
|
|
|
|
|
return []
|
|
|
|
|
|
|
|
|
|
return [cls.de_json(operator, client) for operator in data]
|