from .base import Base
from ..utils.errors import WrongConverterError
from ..utils.document_converter import run_shell_command
from pathlib import Path

class TxtConverter(Base):
    def __init__(self) -> None:
        super().__init__()

    def convert(self, input_file_path: str, output_file_format: str):
        super().initialize_details(input_file_path, output_file_format)
        if(self.input_file_format != ".txt"):
            raise WrongConverterError("TxtConverter", self.input_file_format)        
        if(self.input_file_format == self.output_file_format):
            return "Output file format is the same as input file format", False
        else:
            format = self.output_file_format.replace(".","")
            shell_command = f'soffice --headless --convert-to {format} "{self.input_file_path}" --outdir "{Path(self.input_file_path).parent}"'
            print(f"Shell Command: {shell_command}") 
            return run_shell_command(shell_command)


 