from django.db import models

# Create your models here.

class Author(models.Model):
    name        = models.CharField(max_length=255)
    authorId    = models.IntegerField()

    def __str__(self):
        return self.name

class Level(models.Model):
    author      = models.ForeignKey(Author, on_delete=models.DO_NOTHING)
    title       = models.CharField(max_length=16)
    levelId     = models.IntegerField()
    darts       = models.IntegerField()
    target      = models.IntegerField()
    plays       = models.IntegerField()
    completions = models.IntegerField()
    rating      = models.FloatField(null=True, blank=True)
    data        = models.CharField(max_length=288)

    def __str__(self):
        return f"{self.author} - {self.title}"


    def getFlashVars(self, seperator):
        flashVars = {
            "levelNum": self.levelId,
            "title": self.title,
            "darts": self.darts,
            "target": self.target,
            "data": self.data,
            "authorID": self.author.authorId,
            "numCompleted": self.completions,
            "rating": self.rating if self.rating else 0.0,
        }
        flashVarsStr = f"{seperator}".join([f"{k}={v}"
                                            for k, v in flashVars.items()])
        return flashVarsStr


class Player(models.Model):
    pass