import json from typing import Optional, List, Dict class Attachment: def __init__(self, filename: str, data: str): self.filename = filename self.data = data class Message: def __init__(self, message_id: str, body: Optional[str], attachments: Optional[List[Attachment]], company: str , body_len:int , attachment_len:int): self.id = message_id self.body = body self.attachments = attachments self.company = company self.body_len = body_len self.attachment_len = attachment_len def to_json(self): return { "id": self.id, "body": self.body, "attachments": [attachment.__dict__ for attachment in self.attachments] if self.attachments else None, "company": self.company, "body_len" : self.body_len, "attachemnt_len" : self.attachment_len }