from helpers.either import Either, Left, Right
from repository.freecad_repository import (
    FreeCadRepository,
)


class OpenFreeCadDocumentUseCase:
    """A class that checks open documents, closes them and opens the one with which the program will work"""

    def call(path: str) -> Either:
        try:
            FreeCadRepository().closeIfOpenDocument()
            FreeCadRepository().openDocument(path)
            return Left(None)
        except Exception as e:
            print(e)
            print("OpenFreeCadDocumentUseCase error")
            return Right(None)
