from django.db import models
from django.conf import settings

class Project(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE)
    title = models.CharField(max_length=200)
    industry = models.CharField(max_length=100)
    goal = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.title

class MindMapNode(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='nodes')
    title = models.CharField(max_length=200)
    summary = models.TextField()
    category = models.CharField(max_length=100)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return self.title

class MindMapConnection(models.Model):
    project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name='connections')
    source = models.ForeignKey(MindMapNode, on_delete=models.CASCADE, related_name='outgoing_connections')
    target = models.ForeignKey(MindMapNode, on_delete=models.CASCADE, related_name='incoming_connections')
    how = models.TextField(help_text="How they connect")
    why = models.TextField(help_text="Why they connect")
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.source.title} -> {self.target.title}"