from django.db import models

# Create your models here.


class Experiment(models.Model):
    name = models.TextField()
    enabled = models.BooleanField(default=False)
    condition = models.TextField(default='False')
    project = models.ForeignKey('web.Project', on_delete=models.CASCADE)
    stage = models.TextField(default='production')

    class Meta:
        indexes = [
            models.Index(fields=['project', 'stage']),
            models.Index(fields=['project', 'name', 'stage'])
        ]

    @property
    def exp_type(self):
        if self.condition == 'False':
            return 0
        if self.condition == 'user.is_superuser':
            return 1
        if self.condition == 'user.platform_staff':
            return 2
        if self.condition == 'True':
            return 3
        return 4