from django.db import models

class Product(models.Model):
    """
    Stores product details
    """
    item_id = models.CharField(max_length=100, unique=True)
    product_name = models.CharField(max_length=255)
    product_long_description = models.TextField(blank=True, null=True)
    product_short_description = models.TextField(blank=True, null=True)
    product_type = models.CharField(max_length=100, blank=True, null=True)
    image_path = models.CharField(max_length=500, blank=True, null=True)
    image = models.ImageField(upload_to='products/', blank=True, null=True)

    def __str__(self):
        return f"{self.product_name} ({self.item_id})"




class ProductType(models.Model):
    name = models.CharField(max_length=100, unique=True)

    def __str__(self):
        return self.name



class ProductAttribute(models.Model):
    product_type = models.ForeignKey(ProductType, on_delete=models.CASCADE, related_name="attributes")
    name = models.CharField(max_length=100)
    is_mandatory = models.BooleanField(default=False)

    def __str__(self):
        return f"{self.product_type.name} - {self.name} ({'Mandatory' if self.is_mandatory else 'Additional'})"



class AttributePossibleValue(models.Model):
    attribute = models.ForeignKey(ProductAttribute, on_delete=models.CASCADE, related_name="possible_values")
    value = models.CharField(max_length=255)

    def __str__(self):
        return f"{self.attribute.name}: {self.value}"
