o
    4j%                     @   sB   d dl mZmZmZ d dlmZ d dlmZ eG dd dZdS )    )	dataclassfieldasdict)datetime)Optionalc                   @   s   e Zd ZU dZeed< eed< eed< eed< eed< dZeed< dZeed	< d
efddZ	e
ded
efddZe
ded
efddZdS )EPGEntryz9Represents a single EPG (Electronic Program Guide) entry.titleimagechannelstartend descriptioncategoryreturnc                 C   s>   | j | j| j| j| jd}| jr| j|d< | jr| j|d< |S )z"Convert to the output JSON format.)r   r	   r
   r   r   r   r   )r   r	   r
   r   r   r   r   )selfresult r   6/var/www/addictedbytheproject.nl/epg_general/models.pyto_dict   s   

zEPGEntry.to_dictdtc                 C   s.   | j du rddlm} | j|dd} |  S )zAFormat a datetime object to ISO 8601 string with timezone offset.Nr   ZoneInfoEurope/Rome)tzinfo)r   zoneinfor   replace	isoformat)r   r   r   r   r   format_datetime_iso!   s   
zEPGEntry.format_datetime_isoepoch_msc                 C   s*   ddl m} tj| d |dd}| S )zAConvert epoch milliseconds to ISO 8601 string with Rome timezone.r   r   i  r   )tz)r   r   r   fromtimestampr   )r   r   r   r   r   r   epoch_ms_to_iso*   s   zEPGEntry.epoch_ms_to_isoN)__name__
__module____qualname____doc__str__annotations__r   r   dictr   staticmethodr   r   intr"   r   r   r   r   r      s   
 r   N)dataclassesr   r   r   r   typingr   r   r   r   r   r   <module>   s
    