74 Zeilen
2.0 KiB
Python
74 Zeilen
2.0 KiB
Python
"""
|
|
Platform Entity - Represents a social media platform
|
|
"""
|
|
from dataclasses import dataclass
|
|
from typing import Optional, Dict, Any
|
|
from enum import Enum
|
|
|
|
|
|
class PlatformStatus(Enum):
|
|
"""Platform availability status"""
|
|
ENABLED = "enabled"
|
|
DISABLED = "disabled"
|
|
UPCOMING = "upcoming"
|
|
|
|
|
|
@dataclass
|
|
class Platform:
|
|
"""
|
|
Platform entity representing a social media platform.
|
|
Clean Architecture: Domain Entity
|
|
"""
|
|
id: str
|
|
display_name: str
|
|
status: PlatformStatus
|
|
icon: str
|
|
color: str
|
|
|
|
def __init__(
|
|
self,
|
|
id: str,
|
|
display_name: str,
|
|
enabled: bool = True,
|
|
icon: str = None,
|
|
color: str = "#000000"
|
|
):
|
|
self.id = id
|
|
self.display_name = display_name
|
|
self.status = PlatformStatus.ENABLED if enabled else PlatformStatus.DISABLED
|
|
self.icon = icon or f"{id}.svg"
|
|
self.color = color
|
|
|
|
@property
|
|
def is_enabled(self) -> bool:
|
|
"""Check if platform is enabled"""
|
|
return self.status == PlatformStatus.ENABLED
|
|
|
|
@property
|
|
def is_disabled(self) -> bool:
|
|
"""Check if platform is disabled"""
|
|
return self.status == PlatformStatus.DISABLED
|
|
|
|
def to_dict(self) -> Dict[str, Any]:
|
|
"""Convert to dictionary"""
|
|
return {
|
|
'id': self.id,
|
|
'display_name': self.display_name,
|
|
'status': self.status.value,
|
|
'icon': self.icon,
|
|
'color': self.color
|
|
}
|
|
|
|
@classmethod
|
|
def from_dict(cls, data: Dict[str, Any]) -> 'Platform':
|
|
"""Create from dictionary"""
|
|
return cls(
|
|
id=data.get('id'),
|
|
display_name=data.get('display_name'),
|
|
enabled=data.get('enabled', True),
|
|
icon=data.get('icon'),
|
|
color=data.get('color', '#000000')
|
|
)
|
|
|
|
def __repr__(self) -> str:
|
|
return f"Platform(id={self.id}, name={self.display_name}, status={self.status.value})" |