from django.db import models
from django.conf import settings


class Shop(models.Model):	
	shop_type   = models.CharField(max_length=100)
	shop_id     = models.CharField(max_length=100)
	latitude    = models.FloatField()
	longitude   = models.FloatField()	
	shope_name  = models.CharField(max_length=100)
	shop        = models.CharField(max_length=100)
	addr_city   = models.CharField(max_length=100, blank=True, null=True)
	addr_street = models.CharField(max_length=100, blank=True, null=True)
	

	def __str__(self):
		return self.shop_name


class Category(models.Model):	
	shop_name = models.ForeignKey(Shop, on_delete = models.CASCADE)
	shop_cat  = models.CharField(max_length=100)

	def __str__(self):
		return self.shop_cat


class Item(models.Model):
	shop_cat = models.ForeignKey(Category, on_delete = models.CASCADE)
	title    = models.CharField(max_length=100)
	price    = models.FloatField()

	def __str__(self):
		return self.title


class OrderItem(models.Model):
	item = models.ForeignKey(Item, on_delete = models.CASCADE)

	def __str__(self):
		return self.item


class Order(models.Model):
	user         = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete = models.CASCADE)
	items        = models.ManyToManyField(OrderItem)
	start_date   = models.DateTimeField(auto_now_add = True)
	ordered_date = models.DateTimeField()
	ordered      = models.BooleanField(default=False)

	def __str__(self):
		return self.user.username
