from __future__ import annotations

from dataclasses import dataclass
from typing import Any, Dict


@dataclass
class Neo4jPresetConfig:

    neo4j_uri: str
    neo4j_username: str
    neo4j_password: str
    readonly: bool = False

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> Neo4jPresetConfig:
        kwargs = { 
            "neo4j_uri": data["neo4j_uri"],
            "neo4j_username": data["neo4j_username"],
            "neo4j_password": data["neo4j_password"]
        }  
        if "readonly" in data:  
            kwargs["readonly"] = data["readonly"]

        return cls(**kwargs)  

    def to_dict(self) -> Dict[str, Any]:
        return {
            "neo4j_uri": self.neo4j_uri,
            "neo4j_username": self.neo4j_username,
            "readonly": self.readonly,
        }
