import uuid
from django.db import models
from paycode.models import Paycode

class Function(models.Model):
    id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
    name = models.CharField(max_length=100)
    out = models.BooleanField(default=False)
    break_flag = models.BooleanField(
        default=False,
        help_text="True if this stamp marks the start or end of an official break period."                                                                      
    )
    with_reason = models.BooleanField(
        default=False,
        help_text="True if this function requires a reason to be provided."
    )
    paycode = models.ForeignKey(Paycode, on_delete=models.CASCADE, related_name='functions', null=True, blank=True)
    pre_function = models.BooleanField(default=False)
    function_ref_id = models.CharField(max_length=100, blank=True)
    question_type = models.CharField(
        max_length=20,
        choices=[
            ('none', 'None'),
            ('clock_in', 'Clock In'),
            ('clock_out', 'Clock Out'),
            ('lunch_in', 'Lunch In'),
            ('lunch_out', 'Lunch Out'),
            ('break_in', 'Break In'),
            ('break_out', 'Break Out'),
        ],
        default='none',
        help_text="Type of question/action"
    )
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        if self.paycode:
            return f"{self.name} - {self.paycode.paycode}"
        return f"{self.name}"

    class Meta:
        ordering = ['-created_at']
