from django.db import models
from django.core.validators import validate_unicode_slug, MaxLengthValidator#, MaxValueValidator, URLValidator
# Create your models here.

class Event(models.Model):
    slug = models.SlugField(
        db_index=True,
        unique=True,
        validators=[validate_unicode_slug],
    )
    name = models.CharField(
        max_length=50,
        validators=[MaxLengthValidator(50)],
    )
    description = models.CharField(
        null=True,
        blank=True,
        max_length=200,
        validators=[MaxLengthValidator(200)],
    )
    location = models.ForeignKey(
        'Location',
        on_delete=models.PROTECT,
    )
    doors_open = models.DateTimeField(
        null=True,
        blank=True,
    )
    doors_close = models.DateTimeField(
        null=True,
        blank=True,
    )
    price = models.DecimalField(
        decimal_places=2,
        max_digits=5,
    )
    wardrobe = models.DecimalField(
        null=True,
        default=None,
        decimal_places=2,
        max_digits=4,
    )
    wardrobe_guarded = models.BooleanField(
        default=False
    )
    dresscode = models.CharField(
        max_length=50,
        validators=[MaxLengthValidator(50)],
    )

    #class Meta:
    #    ordering = ['doors_open']

    def __str__(self):
        return self.name


class Location(models.Model):
    name = models.CharField(
        max_length=50,
        validators=[MaxLengthValidator(50)],
    )
    venue_type = models.CharField(
        max_length=30,
        validators=[MaxLengthValidator(30)],
    )
    street = models.CharField(
        max_length=50,
        validators=[MaxLengthValidator(50)],
    )
    housenumber = models.CharField(
        max_length=10,
        validators=[MaxLengthValidator(10)],
    )
    city = models.CharField(
        max_length=30,
        validators=[MaxLengthValidator(30)],
    )
    areacode = models.CharField(
        null=True,
        blank=True,
        max_length=10,
        validators=[MaxLengthValidator(10)],
    )
    free_parking = models.PositiveSmallIntegerField(
        default=False,
    )
    class Meta:
        #db_table = 'app_version'
        constraints = [
            models.UniqueConstraint(fields=['street', 'housenumber'], name='unique location')
        ]
        ordering = ['name']

    def __str__(self):
        return self.name


class Activity(models.Model):
    event = models.ForeignKey(
        'Event',
        on_delete=models.CASCADE,
    )
    area = models.ForeignKey(
        'Area',
        on_delete=models.CASCADE,
    )
    name = models.CharField(
        null=True,
        blank=True,
        max_length=50,
        default='Social',
        validators=[MaxLengthValidator(50)],
    )
    description = models.CharField(
        null=True,
        blank=True,
        max_length=200,
        validators=[MaxLengthValidator(200)],
    )
    TYPE_CHOICES = [
        ('Dance party',
            (
                ('sc', 'Social'),
                ('gl', 'Gala'),
            )
        ),
        ('ws', 'Workshop'),
        ('sh', 'Show'),
        ('cl', 'Class'),
        ('br', 'Break'),
        ('ot', 'Other'),
    ]
    type = models.CharField(
        max_length=2,
        choices=TYPE_CHOICES,
        default='sc',
        validators=[MaxLengthValidator(2)],
    )
    start = models.DateTimeField()
    end = models.DateTimeField()
    artist = models.CharField(
        null=True,
        blank=True,
        max_length=50,
        validators=[MaxLengthValidator(50)],
    )

    #class Meta:
    #    ordering = ['name']

    def __str__(self):
        return self.name


class Area(models.Model):
    name = models.CharField(
        max_length=50,
        default='Main',
        validators=[MaxLengthValidator(50)],
    )

    def __str__(self):
        return self.name
