from django.db import models
from django.contrib import admin
from polymorphic.models import PolymorphicModel

##
# Products
#
PRODUCT_TYPE_CHOICES = (
    ('RentalProduct', 'Rental Product'),
    ('IndividualProduct', 'Individual Product'),
    ('BulkProduct', 'Bulk Product'),
)
class Product(PolymorphicModel):
    '''Product Superclass'''
    name = models.TextField(null=True, blank=True)
    description = models.TextField(null=True, blank=True)
    created_on = models.DateTimeField(null=True, blank=True, auto_now_add=True)
    image = models.TextField(null=True, blank=True)

    def __str__(self):
        return 'Abstract Product: %s' % (self.name)

admin.site.register(Product)


RENTAL_STATUS_CHOICES = (
    ('current', 'Rentable'),
    ('damaged', 'Damaged'),
    ('retired', 'No Longer Rentable'),
)
RENTAL_STATUS_CHOICES_MAP = dict(RENTAL_STATUS_CHOICES)
class RentalProduct(Product):
    '''A rental product'''
    status = models.TextField(null=True, blank=True, choices=RENTAL_STATUS_CHOICES)
    # This links it to an actual rental
    # rental = models.ForeignKey('Rental', null=True)

    def __str__(self):
        return 'Rental: %s' % self.name

admin.site.register(RentalProduct)


class IndividualProduct(Product):
    '''A unique, one-off product'''
    creator = models.ForeignKey('account.User')

    def __str__(self):
        return 'Individual Product: %s' % self.name

admin.site.register(IndividualProduct)


class BulkProduct(Product):
    '''A mass-produced product'''
    quantity = models.IntegerField(default=0)

    def __str__(self):
        return 'Bulk Product: %s' % self.name

admin.site.register(BulkProduct)

class Event(models.Model):
    name = models.TextField(null=True, blank=True)
    description = models.TextField(null=True, blank=True)
    start_date = models.DateTimeField(null=True, blank=True, auto_now_add=True)
    end_date = models.DateTimeField(null=True, blank=True, auto_now_add=True)
    venue = models.ForeignKey('catalog.Venue', null=True, blank=True)

admin.site.register(Event)

class Venue(models.Model):
    name = models.TextField(null=True, blank=True)
    description = models.TextField(null=True, blank=True)
    created_on = models.DateTimeField(null=True, blank=True, auto_now_add=True)
    image = models.TextField(null=True, blank=True)
    address = models.TextField(null=True, blank=True)
    city = models.TextField(null=True, blank=True)
    state = models.TextField(null=True, blank=True)
    zip_code = models.TextField(null=True, blank=True)

    def __str__(self):
        return self.name

admin.site.register(Venue)

class Area(models.Model):
    name = models.TextField(null=True, blank=True)
    description = models.TextField(null=True, blank=True)
    created_on = models.DateTimeField(null=True, blank=True, auto_now_add=True)
    place_number = models.IntegerField(null=True, blank=True)
    event = models.ForeignKey('catalog.Event', null=True, blank=True)


admin.site.register(Area)
