from django.db import models
from pxy_openai.assistants import OpenAIAssistant

class FacebookPageAssistant(models.Model):
    """
    Model to link a Facebook page to an OpenAI assistant and manage webhook subscriptions.
    """
    page_id = models.CharField(max_length=100, unique=True, help_text="Unique ID of the Facebook page")
    page_name = models.CharField(max_length=200, help_text="Name of the Facebook page")
    assistant = models.ForeignKey('pxy_openai.OpenAIAssistant', on_delete=models.CASCADE, related_name="facebook_pages")
    is_subscribed = models.BooleanField(default=False, help_text="Indicates if the page is subscribed to webhooks")
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"{self.page_name} ({self.page_id}) -> {self.assistant.name}"

