from django.db import models


class Hero(models.Model):
    PRIMARY_ATTR_STRENGTH = "Strength"
    PRIMARY_ATTR_AGILITY = "Agility"
    PRIMARY_ATTR_INTELLIGENCE = "Intelligence"

    PRIMARY_CHOICES = (
        (PRIMARY_ATTR_STRENGTH, "Strength"),
        (PRIMARY_ATTR_AGILITY, "Agility"),
        (PRIMARY_ATTR_INTELLIGENCE, "Intelligence"),
    )

    name = models.CharField(max_length=200)
    primary = models.CharField(max_length=20, choices=PRIMARY_CHOICES)

    def __str__(self) -> str:  # pragma: no cover - convenience only
        return f"{self.name} ({self.primary})"


class Item(models.Model):
    name = models.CharField(max_length=200)

    def __str__(self) -> str:  # pragma: no cover - convenience only
        return self.name


class Aspect(models.Model):
    hero = models.ForeignKey(Hero, on_delete=models.CASCADE, related_name="aspects")
    name = models.CharField(max_length=200)

    class Meta:
        unique_together = ["hero", "name"]

    def __str__(self) -> str:  # pragma: no cover - convenience only
        return f"{self.hero.name} - {self.name}"


class BuildOfDay(models.Model):
    date = models.DateField(unique=True)
    hero = models.ForeignKey(Hero, on_delete=models.CASCADE)
    items = models.ManyToManyField(Item)
    skill_build = models.JSONField(default=dict)
    aspect = models.CharField(max_length=200, blank=True, null=True)

    def __str__(self) -> str:  # pragma: no cover - convenience only
        return f"Build of {self.date} - {self.hero.name}"
