from django.db import models
from exercise.models import *
from registered_user.models import RegisteredUser

WORKOUT_LEVEL = (
    (1, "easy"),
    (2, "moderate"),
    (3, "average"),
    (4, "hard"),
    (5, "death"),
)

# Create your models here.
class Workout(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    name = models.CharField(max_length=255)
    description = models.CharField(null=True, blank=True, max_length=255)
    registered_user = models.ForeignKey(
      RegisteredUser,
      on_delete=models.CASCADE
    )

    def __str__(self):
        return self.name #+ " : " + self.description + " | by: " + self.registered_user.nick_name

class WorkoutExercise(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    workout = models.ForeignKey(
      Workout,
      on_delete=models.CASCADE,
      related_name='workout_exercise_workout'
    )
    exercise = models.ForeignKey(
      Exercise,
      on_delete=models.CASCADE,
      related_name='workout_exercise_exercise'
    )
    weight = models.IntegerField(null=True, blank=True, max_length=4)
    reps = models.IntegerField(null=True, blank=True, max_length=4)
    duration = models.IntegerField(null=True, blank=True, max_length=4)

    def __str__(self):
        return self.workout.name + " : " + self.exercise.name
    
    def duration_audio(self): 
        if self.duration is not None:
            return str(settings.MEDIA_URL) + "quantities_audio/" + "for_"+str(self.duration)+"_seconds.m4a"

    def weight_audio(self): 
        if self.weight is not None:
            return str(settings.MEDIA_URL) + "quantities_audio/" + "for_"+str(self.weight)+"_pounds.m4a"
    
class CompletedWorkout(models.Model):
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    registered_user = models.ForeignKey(
      RegisteredUser,
      on_delete=models.CASCADE,
      related_name='completed_workout_user'
    )
    workout = models.ForeignKey(
      Workout,
      on_delete=models.CASCADE,
      related_name='completed_workout_workout'
    )
    difficulty = models.PositiveSmallIntegerField(
      choices=WORKOUT_LEVEL
    )
    total_time = models.IntegerField(null=True, blank=True)
    workout_start_time = models.DateTimeField(null=False, blank=False)
    notes = models.TextField(null=False, blank=False)
    total_calories = models.FloatField(null=True, blank=True)

    def __str__(self):
        return self.registered_user.first_name  + " : " + self.registered_user.last_name + " : " + self.workout.name + " : " + str(self.difficulty)