from __future__ import annotations

import uuid
from datetime import datetime
from typing import Any

from sqlalchemy import DateTime, ForeignKey, String, Text, func
from sqlalchemy.orm import Mapped, mapped_column, relationship
from sqlalchemy.types import JSON

from app.db.base_class import Base


class HermesRiskReport(Base):
    __tablename__ = "hermes_risk_reports"

    id: Mapped[str] = mapped_column(String(36), primary_key=True, default=lambda: str(uuid.uuid4()))
    claim_id: Mapped[str] = mapped_column(ForeignKey("expense_claims.id"), index=True)
    execution_log_id: Mapped[str] = mapped_column(ForeignKey("hermes_task_execution_logs.id"), index=True)
    
    risk_level: Mapped[str] = mapped_column(String(20), index=True)
    risk_type: Mapped[str] = mapped_column(String(50), index=True)
    risk_description: Mapped[str] = mapped_column(Text())
    
    related_claim_ids: Mapped[list[str]] = mapped_column(JSON, default=list)
    status: Mapped[str] = mapped_column(String(30), default="pending_review", index=True)
    
    created_at: Mapped[datetime] = mapped_column(DateTime(timezone=True), server_default=func.now())
    updated_at: Mapped[datetime] = mapped_column(
        DateTime(timezone=True), server_default=func.now(), onupdate=func.now()
    )

    claim = relationship("ExpenseClaim", foreign_keys=[claim_id])
    execution_log = relationship("HermesTaskExecutionLog", foreign_keys=[execution_log_id])
