from django import models

from ecommerce.models import Product


class TechnicalSpecification(models.Model):
    """
    One row of the 'Technical specifications' table.
    You can also split into more specific models if needed.
    """
    product = models.OneToOneField(Product, on_delete=models.CASCADE,
                                   related_name="technical_spec")

    # Left column [image:1]
    lamp = models.CharField(max_length=50, default="LED")     # [image:1]
    wattage = models.PositiveSmallIntegerField()              # 6 / 10 / 13 etc. [image:1]
    control = models.CharField(max_length=100)                # "Switch only" [image:1]
    cri = models.PositiveSmallIntegerField()                  # Color Rendering Index >90 [image:1]
    sdcm = models.CharField(max_length=20)                    # e.g. "2,0/3,0" [image:1]
    diameter_mm = models.CharField(max_length=50)             # "Ø90 x 85 H" or similar [image:1]
    ip_rating = models.CharField(max_length=10)               # "IP65" / "IP68" etc. [image:1]
    glow_wire_test = models.CharField(max_length=20)          # "850°" [image:1]
    beam_angle = models.CharField(max_length=20)              # "24°", "36°" [image:1]

    # Right column [image:1]
    chip = models.CharField(max_length=50, default="COB")     # [image:1]
    cct = models.CharField(max_length=20)                     # "2700K", "3000K" etc. [image:1]
    voltage = models.CharField(max_length=50)                 # "85-265V 50/60Hz" [image:1]
    ugr = models.CharField(max_length=20, blank=True)         # "<19" etc. [image:1]
    color = models.CharField(max_length=50, default="White")  # body color [image:1]
    cutout_mm = models.PositiveSmallIntegerField()            # "80" [image:1]
    temp_min = models.SmallIntegerField()                     # 25 for 25°C [image:1]
    temp_max = models.SmallIntegerField()                     # 55 for 55°C [image:1]
    energy_class = models.CharField(max_length=10)            # "A++" [image:1]
    lumen = models.PositiveSmallIntegerField()                # "720lm" [image:1]

    def __str__(self):
        return f"Technical specs for {self.product.name}"