from repository.file_system_repository import FileSystemRepository
from helpers.either import Left, Right, Either


class ReadFileSystemAndGetInstanceModelUseCase:
    def call(self, model, path) -> Either:
        if hasattr(model, "from_dict") is False:
            return Right(
                "ReadFileSystemAndGetInstanceModelUseCase error:"
                + model
                + "is not have method"
                + "from_dict()"
            )
        try:
            return Left(model.from_dict(FileSystemRepository.readJSON(path)))
        except Exception as e:
            print(e)
            error = str(model) + "  " + "from dict error " + "path: " + path
            print("ReadFileSystemAndGetInstanceModelUseCase error" + error)
            return Right(error)
        pass
