from __future__ import annotations from typing import Any, Optional from sqlmodel import Session, select from infrastructure.postgres.solar_table import SolarBuildingInsightsRow from repositories.solar.solar_repository import SolarRepository class SolarPostgresRepository(SolarRepository): def __init__(self, session: Session) -> None: self._session = session def save(self, property_id: int, insights: dict[str, Any]) -> None: existing = self._session.exec( select(SolarBuildingInsightsRow).where( SolarBuildingInsightsRow.property_id == property_id ) ).first() if existing is None: self._session.add( SolarBuildingInsightsRow(property_id=property_id, insights=insights) ) else: existing.insights = insights self._session.add(existing) def get(self, property_id: int) -> Optional[dict[str, Any]]: row = self._session.exec( select(SolarBuildingInsightsRow).where( SolarBuildingInsightsRow.property_id == property_id ) ).first() return row.insights if row is not None else None