import os
from abc import ABC, abstractmethod
from core.config import MAX_SINGLE_CHUNK_SIZE


# 文档基类
class DocBase(ABC):
    def __init__(self, **kwargs):
        self._doc_path = None
        self._doc_name = None
        self._kwargs = kwargs
        self._max_single_chunk_size = kwargs.get(
            "max_single_chunk_size", MAX_SINGLE_CHUNK_SIZE
        )

    @abstractmethod
    def load(self, doc_path):
        """加载文件内容，初始化内部状态。"""
        pass

    @abstractmethod
    def adjust_chunk_size(self):
        pass

    @abstractmethod
    async def get_from_ocr(self):
        pass

    # 根据chunk_id获取文档片段
    @abstractmethod
    def get_chunk_item(self, chunk_id):
        pass

    # 获取文档片段信息
    @abstractmethod
    def get_chunk_info(self, chunk_id):
        pass

    @abstractmethod
    def get_chunk_location(self, chunk_id):
        pass

    # 新增片段批注
    @abstractmethod
    def add_chunk_comment(self, chunk_id, comments):
        pass

    # 编辑片段批注
    @abstractmethod
    def edit_chunk_comment(self, comments):
        pass

    @abstractmethod
    def delete_chunk_comment(self, comments):
        pass

    @abstractmethod
    def get_chunk_id_list(self, step=1):
        pass

    # 获取文档片段数量
    @abstractmethod
    def get_chunk_num(self):
        pass

    # 获取文档片段大小
    @abstractmethod
    def get_all_text(self):
        pass

    # 保存文档到路径
    def to_file(self, path, **kwargs):
        pass

    def release(self):
        if self._doc_path and os.path.exists(self._doc_path):
            os.remove(self._doc_path)
