from datetime import datetime

class Record:
    def __init__(self,
                 standard_name: str,
                 chapter_name: str,
                 section_name: str,
                 subsection_name: str,
                 pdf_path: str,
                 image_path: str,
                 markdown_text: str,
                 id: int = None,
                 created_at: datetime = None,
                 updated_at: datetime = None):
        self.id = id  # 自增ID
        self.standard_name = standard_name  # 标准名称
        self.chapter_name = chapter_name  # 章节名称
        self.section_name = section_name  # 节名称
        self.subsection_name = subsection_name  # 小节名称
        self.pdf_path = pdf_path  # PDF路径
        self.image_path = image_path  # 图片路径
        self.markdown_text = markdown_text  # Markdown文本
        self.created_at = created_at or datetime.now()  # 创建时间
        self.updated_at = updated_at or datetime.now()  # 更新时间

    def to_dict(self):
        return {
            'id': self.id,
            'standard_name': self.standard_name,
            'chapter_name': self.chapter_name,
            'section_name': self.section_name,
            'subsection_name': self.subsection_name,
            'pdf_path': self.pdf_path,
            'image_path': self.image_path,
            'markdown_text': self.markdown_text,
            'created_at': self.created_at.strftime('%Y-%m-%d %H:%M:%S'),
            'updated_at': self.updated_at.strftime('%Y-%m-%d %H:%M:%S')
        }