from datetime import datetime
from sqlalchemy import (
JSON,
TIMESTAMP,
ForeignKey,
Index,
Integer,
Numeric,
SmallInteger,
String,
Text,
func,
)
from sqlalchemy.orm import Mapped, mapped_column
from vmk_data_collector.db.base import Base
class AiEnrichment(Base):
__tablename__ = "ai_enrichments"
id: Mapped[int] = mapped_column(Integer, primary_key=True)
property_id: Mapped[int] = mapped_column(
ForeignKey("property_listings.id", ondelete="CASCADE"),
nullable=False,
unique=True,
)
extracted_features: Mapped[dict] = mapped_column(JSON, default=dict)
price_assessment: Mapped[dict] = mapped_column(JSON, default=dict)
listing_quality_score: Mapped[int | None] = mapped_column(SmallInteger)
reliability_rating: Mapped[int | None] = mapped_column(SmallInteger)
sentiment_score: Mapped[float | None] = mapped_column(Numeric(3, 2))
classification: Mapped[str | None] = mapped_column(String(64))
image_analysis_results: Mapped[dict] = mapped_column(JSON, default=dict)
generated_description: Mapped[str | None] = mapped_column(Text)
summary: Mapped[str | None] = mapped_column(Text)
model_version: Mapped[str | None] = mapped_column(String(64))
processing_time_ms: Mapped[int | None] = mapped_column(Integer)
created_at: Mapped[datetime] = mapped_column(
TIMESTAMP(timezone=True), server_default=func.now()
)
__table_args__ = (Index("ix_ai_enrichments_property_id", "property_id"),)