from sqlalchemy import Column, String, ForeignKey
from sqlalchemy.orm import relationship

from atst.models import Base, types, mixins


class RequestInternalComment(Base, mixins.TimestampsMixin):
    __tablename__ = "request_internal_comments"

    id = types.Id()
    text = Column(String(), nullable=False)

    user_id = Column(ForeignKey("users.id"), nullable=False)
    user = relationship("User")

    request_id = Column(ForeignKey("requests.id", ondelete="CASCADE"), nullable=False)
    request = relationship("Request")

    def __repr__(self):
        return "<RequestInternalComment(text='{}', user='{}', request='{}', id='{}')>".format(
            self.text, self.user.full_name, self.request_id, self.id
        )
