"""
Domain analysis cache (Phase 2 Diligence).

We store computed JSON to avoid repeated RDAP/DNS/HTTP checks on each click.
"""

from __future__ import annotations

from datetime import datetime

from sqlalchemy import DateTime, Integer, String, Text
from sqlalchemy.orm import Mapped, mapped_column

from app.database import Base


class DomainAnalysisCache(Base):
    __tablename__ = "domain_analysis_cache"

    id: Mapped[int] = mapped_column(primary_key=True, index=True)
    domain: Mapped[str] = mapped_column(String(255), unique=True, index=True, nullable=False)
    payload_json: Mapped[str] = mapped_column(Text, nullable=False)
    computed_at: Mapped[datetime] = mapped_column(DateTime, default=datetime.utcnow, index=True)
    ttl_seconds: Mapped[int] = mapped_column(Integer, default=3600)

