from sqlalchemy import Column, Integer, String, DateTime, Text, Float, func
from app.database import Base


class MessageLog(Base):
    """L1报文日志"""
    __tablename__ = "message_logs"

    id = Column(Integer, primary_key=True, index=True)
    msg_id = Column(String(50), index=True, comment="报文ID")
    msg_type = Column(String(30), index=True, comment="报文类型")
    direction = Column(String(10), comment="方向: recv/send")
    source = Column(String(50), comment="来源系统")
    raw_data = Column(Text, comment="原始报文")
    parsed_data = Column(Text, comment="解析结果JSON")
    status = Column(String(20), default="success", comment="处理状态: success/error")
    error_msg = Column(Text, comment="错误信息")
    process_time = Column(Float, comment="处理耗时ms")
    received_at = Column(DateTime, nullable=False, index=True)
    created_at = Column(DateTime, server_default=func.now())
