from django.contrib.auth.models import User
from django.db import models


class Chat(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f'Chat by {self.user.username} on {self.created_at.strftime("%Y-%m-%d")}'


class ChatMessage(models.Model):
    chat = models.ForeignKey(Chat, on_delete=models.CASCADE)
    message = models.TextField()
    is_user = models.BooleanField(default=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f'Message from {"User" if self.is_user else "AI"} in chat {self.chat.id} on {self.created_at.strftime("%Y-%m-%d")}'


class Post(models.Model):
    author = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=200)
    slug = models.SlugField(unique=True)
    content = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)
    intent = models.CharField(max_length=50, default='Neutral')

    def __str__(self):
        return f'Post by {self.author.username} on {self.created_at.strftime("%Y-%m-%d")}'