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

class Item(models.Model):
    name = models.CharField(max_length=100)
    description = models.TextField()

    def __str__(self):
        return self.name

class Quest(models.Model):
    title = models.CharField(max_length=100)
    description = models.TextField()
    is_active = models.BooleanField(default=False)
    is_completed = models.BooleanField(default=False)

    def __str__(self):
        return self.title

class Scene(models.Model):
    title = models.CharField(max_length=200)
    content = models.TextField()
    
    def __str__(self):
        return self.title

class Choice(models.Model):
    scene = models.ForeignKey(Scene, related_name='choices', on_delete=models.CASCADE)
    text = models.CharField(max_length=200)
    next_scene = models.ForeignKey(Scene, related_name='incoming_choices', on_delete=models.SET_NULL, null=True, blank=True)
    
    def __str__(self):
        return self.text

class PlayerProfile(models.Model):
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    current_scene = models.ForeignKey(Scene, on_delete=models.SET_NULL, null=True, blank=True)
    inventory = models.ManyToManyField(Item, blank=True)
    quests = models.ManyToManyField(Quest, blank=True)
    level = models.IntegerField(default=1)
    
    def __str__(self):
        return self.user.username