# models/erp_api_call_log.py

from sqlalchemy import Column, Integer, String, Float, Boolean, DateTime
from datetime import datetime
from database import Base


class ErpApiCallLog(Base):
    """One row per outbound helixta-api -> erp-api call (services/erp_client.py),
    success or failure — lets you count/verify cross-service interactions
    from the database instead of grepping console logs."""

    __tablename__ = "erp_api_call_logs"

    id = Column(Integer, primary_key=True, index=True)

    method = Column(String, nullable=False)
    endpoint = Column(String, nullable=False)
    http_status = Column(Integer, nullable=True)
    latency_ms = Column(Float, nullable=True)
    success = Column(Boolean, nullable=False, default=False)
    error_code = Column(String, nullable=True)

    company_id = Column(Integer, nullable=True)
    conversation_id = Column(String, nullable=True)

    created_at = Column(DateTime, default=datetime.utcnow)
