from __future__ import annotations

from typing import Any, Dict

from pydantic import BaseModel, ConfigDict, SecretStr


class Neo4jPresetConfig(BaseModel):
    model_config = ConfigDict(extra="ignore")

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

    @classmethod
    def from_dict(cls, data: Dict[str, Any]) -> Neo4jPresetConfig:
        return cls.model_validate(data)

    def get_neo4j_password(self) -> str:
        return self.neo4j_password.get_secret_value()

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

    def __repr__(self) -> str:
        return (
            "Neo4jPresetConfig("
            f"neo4j_uri={self.neo4j_uri!r}, "
            f"neo4j_username={self.neo4j_username!r}, "
            "neo4j_password='********', "
            f"readonly={self.readonly!r}"
            ")"
        )
