from django.db import models
from django.urls import reverse
# Create your models here.


class Product(models.Model):
    product_id = models.AutoField
    product_name = models.CharField(max_length=50)
    category = models.CharField(max_length=50, default="")
    subcategory = models.CharField(max_length=50, default="")
    price = models.IntegerField(default=0)
    desc = models.CharField(max_length=300)
    pub_date = models.DateTimeField()
    img = models.ImageField(upload_to='product_images', default="")

    def __str__(self):
        return self.product_name

    def get_absolute_url(self):
        return reverse('shop:prodview', kwargs={'id': self.id})


class Contact(models.Model):
    msg_id = models.AutoField(primary_key=True)
    name = models.CharField(max_length=50, default="")
    email = models.EmailField(max_length=50, default="")
    phone = models.CharField(max_length=20, default="")
    desc = models.CharField(max_length=500, default="")

    def __str__(self):
        return self.name


class Order(models.Model):
    ord_id = models.AutoField(primary_key=True)
    item_json = models.CharField(max_length=5000, default="")
    name = models.CharField(max_length=50, default="")
    email = models.EmailField(max_length=50, default="")
    phone = models.CharField(max_length=20, default="")
    address1 = models.CharField(max_length=300, default="")
    address2 = models.CharField(max_length=300, default="")
    city = models.CharField(max_length=300, default="")
    state = models.CharField(max_length=300, default="")
    zip_code = models.CharField(max_length=30, default="")


class OrderUpdate(models.Model):
    update_id = models.AutoField(primary_key=True)
    order_id = models.IntegerField(default=0)
    update_desc = models.CharField(max_length=5000)
    timestamp = models.DateField(auto_now_add=True)

    def __str__(self):
        return self.update_desc[0:7] + "..."
