from datetime import datetime

class ProjectModel:
    def __init__(self,
                 project_name: str = None,
                 description:str = None,
                 project_id: int = None,
                 delete_by:str = None,
                 deleted_at: datetime = None,
                 create_by: str = None,
                 created_at: datetime = None,
                 update_by: str = None,
                 updated_at: datetime = None,
                 ):
        self.id = project_id
        self.project_name = project_name
        self.description = description
        self.delete_by = delete_by
        self.deleted_at = deleted_at
        self.create_by = create_by
        self.created_at = created_at
        self.update_by = update_by
        self.updated_at = updated_at

    def to_dict(self) -> dict:
        return {
            'id': self.id,
            'project_name': self.project_name,
            'description': self.description,
        }

class SubProjectModel:

    def __init__(self,
                 project_id: int = None,
                 sub_project_name: str = None,
                 work_catalog: str = None,
                 work_content: str = None,
                 standard_version: str = None,
                 file_paths: str = None,
                 status: int = 0,
                 completion_tokens: int = 0,
                 prompt_tokens: int = 0,
                 total_tokens: int = 0,
                 sub_id: int = None,
                 delete_by: str = None,
                 deleted_at: datetime = None,
                 create_by: str = None,
                 created_at: datetime = None,
                 update_by: str = None,
                 updated_at: datetime = None,
                 ):
        self.id = sub_id
        self.project_id = project_id
        self.sub_project_name = sub_project_name
        self.work_catalog = work_catalog
        self.work_content = work_content
        self.standard_version = standard_version
        self.file_paths = file_paths
        self.status = status
        self.completion_tokens = completion_tokens
        self.prompt_tokens = prompt_tokens
        self.total_tokens = total_tokens
        self.delete_by = delete_by
        self.deleted_at = deleted_at
        self.create_by = create_by
        self.created_at = created_at
        self.update_by = update_by
        self.updated_at = updated_at
        self.items = []

    def __str__(self):
        return f"SubProjectModel(id={self.id}, project_no={self.project_id}, project_name={self.sub_project_name}, work_catalog={self.work_catalog}, work_content={self.work_content}, standard_version={self.standard_version}, status={self.status}, completion_tokens={self.completion_tokens}, prompt_tokens={self.prompt_tokens}, total_tokens={self.total_tokens}, updated_at={self.updated_at}, created_at={self.created_at})"

    def get_path(self):
        return f"project/p{self.project_id}/s{self.id}"
    def set_items(self, items: list):
        self.items = items

    def add_item(self, item: 'SubProjectItemModel'):
        self.items.append(item)

    def to_dict(self) -> dict:
        return {
            "id": self.id,
            "project_id": self.project_id,
            "sub_project_name": self.sub_project_name,
            "file_paths": self.file_paths,
            "work_catalog": self.work_catalog,
            "work_content": self.work_content,
            "standard_version": self.standard_version,
            "status": self.status,
        }

class SubProjectItemModel:
    def __init__(self,
                 project_id: int = None,
                 sub_project_id: int=None,
                 device_name: str=None,
                 device_model: str=None,
                 device_unit: str = None,
                 device_count: float = 0,
                 standard_version: str = None,
                 standard_no: str = None,
                 process_status: int = 0,
                 process_time: datetime = None,
                 send_status: int = 0,
                 send_time: datetime = None,
                 item_id: int = None,
                 remark: str = None,
                 updated_at: datetime = None):
        self.id = item_id
        self.project_id = project_id
        self.sub_project_id = sub_project_id
        self.device_name = device_name
        self.device_model = device_model
        self.device_unit = device_unit
        self.device_count = device_count
        self.standard_no = standard_no
        self.standard_version = standard_version
        self.process_status = process_status
        self.process_time = process_time
        self.send_status = send_status
        self.send_time = send_time
        self.remark = remark
        self.updated_at = updated_at

    def __str__(self):
        return f"ProjectItemModel(id={self.id}, project_no={self.sub_project_id}, device_name={self.device_name}, device_model={self.device_model}, device_unit={self.device_unit}, device_count={self.device_count}, standard_no={self.standard_no}, standard_version={self.standard_version})"

    def to_dict(self) -> dict:
        return {
            "id": self.id,
            "project_id": self.project_id,
            "sub_project_id": self.sub_project_id,
            "device_name": self.device_name,
            "device_model": self.device_model,
            "device_unit": self.device_unit,
            "device_count": self.device_count,
            "standard_no": self.standard_no,
            "standard_version": self.standard_version,
            "process_status": self.process_status,
            "process_time": self.process_time,
            "send_status": self.send_status,
            "send_time": self.send_time,
        }
    def to_ai_json(self):
        return {
            "i": self.id,
            "n": self.device_name,
            "m": self.device_model,
            "u": self.device_unit,
            "c": self.device_count,
        }

    @staticmethod
    def list_to_ai_json(items):
        return [item.to_ai_json() for item in items]
