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


class Activity(models.Model):
    class Category(models.TextChoices):
        SOCIAL = 'Social'
        HEALTH = 'Health'
        HOBBIES = 'Hobbies'
        OBLIGATION = 'Obligation'

    name = models.CharField(max_length=255)
    icon = models.CharField(max_length=50)
    category = models.CharField(max_length=50, choices=Category.choices)

    def __str__(self):
        return self.name

class Mission(models.Model):
    title = models.CharField(max_length=255)
    description = models.TextField()
    trigger_mood_score = models.IntegerField()
    is_active = models.BooleanField(default=True)

    def __str__(self):
        return self.title

class MoodEntry(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    date_time = models.DateTimeField(auto_now_add=True)
    mood_score = models.IntegerField()
    note = models.TextField(blank=True, null=True)
    color_code = models.CharField(max_length=7)
    activities = models.ManyToManyField(Activity)
    mission = models.ForeignKey(Mission, on_delete=models.SET_NULL, null=True, blank=True)

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

class Note(models.Model):
    user = models.ForeignKey(User, on_delete=models.CASCADE)
    title = models.CharField(max_length=255)
    content = models.TextField()
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return self.title