# app/api/v1/models/comments.py

from sqlalchemy import Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship
from app.api.db.database import Base

class Comments(Base):
    __tablename__ = 'comments'

    id = Column(Integer, primary_key=True, index=True)
    post_id = Column(Integer, ForeignKey('posts.id'))
    user_id = Column(Integer, ForeignKey('users.id'))
    comment_text = Column(Text)
    created_at = Column(String)
    updated_at = Column(String, nullable=True)

    post = relationship('Post', back_populates='comments')
    user = relationship('User', back_populates='comments')

    def __repr__(self):
        return f'Comment(id={self.id}, post_id={self.post_id}, user_id={self.user_id}, comment_text="{self.comment_text[:20]}...", created_at="{self.created_at}", updated_at="{self.updated_at}")'