from django.db import models
from django.contrib.auth.models import User
class Customer(models.Model):
    user = models.OneToOneField(User,null=True,blank =True,on_delete=models.CASCADE)
    name = models.CharField(max_length=200,null=True)
    email = models.CharField(max_length=200,null=True)
    def __str__(self):
        return self.name
class Product(models.Model):
    category =models.CharField(max_length=100,null=False)
    name = models.CharField(max_length=200, null=True)
    price = models.FloatField(max_length=10,null=False)
    image = models.ImageField(null=True, blank=True)
    description = models.CharField(max_length=400,null=True,blank=True)
    digital = models.BooleanField(default=False, null=True)
    def __str__(self):
        return self.name

class Order(models.Model):
    customer = models.ForeignKey(Customer,on_delete=models.SET_NULL,null=True,blank=True)
    date_ordered = models.DateTimeField(auto_now_add=True)
    complete = models.BooleanField(default=False,null=True,blank=False)
    transaction_id = models.CharField(max_length=100,null=True)
    # def __str__(self):
    #     return self.transaction_id

class OrderItem(models.Model):
	product = models.ForeignKey(Product, on_delete=models.SET_NULL, null=True)
	order = models.ForeignKey(Order, on_delete=models.SET_NULL, null=True)
	quantity = models.IntegerField(default=0, null=True, blank=True)
	date_added = models.DateTimeField(auto_now_add=True)
    
class ShippingAddress(models.Model):
    customer = models.ForeignKey(Customer,on_delete=models.SET_NULL,null=True)
    order = models.ForeignKey(Order,on_delete=models.SET_NULL,null=True)
    address = models.CharField(max_length=200,null=False)
    zipcode = models.CharField(max_length=6,null=False)
    city = models.CharField(max_length=100,null=False)
    state = models.CharField(max_length=200,null=False)
    date_added = models.DateTimeField(auto_now_add=True)
    def __str__(self):
        return self.address


    
         
          





