from dataclasses import dataclass
from logging import Logger
from typing import TypeVar,Generic
from abc import ABC,abstractmethod
from docutranslate.ir.document import Document
from docutranslate.logger import global_logger


@dataclass(kw_only=True)
class TranslatorConfig:
    logger:Logger|None=None

T=TypeVar('T',bound=Document)

class Translator(ABC,Generic[T]):
    """
    翻译中间文本（原地替换），Translator不做格式转换
    """
    def __init__(self,config:TranslatorConfig|None=None):
        self.config=config
        self.logger=config.logger or global_logger
    @abstractmethod
    def translate(self, document:T) -> Document:
        ...
    @abstractmethod
    async def translate_async(self, document: T) -> Document:
        ...