from django.db import models
from django.contrib.auth.models import AbstractUser

class User(AbstractUser):
    ROLE_CHOICES = (
        ('admin', 'Admin'),
        ('manager', 'Manager'),
        ('employee', 'Employee'),
    )
    role = models.CharField(max_length=10, choices=ROLE_CHOICES, default='employee')

class Shift(models.Model):
    start_time = models.DateTimeField()
    end_time = models.DateTimeField()
    employee = models.ForeignKey(User, on_delete=models.CASCADE, related_name='shifts')

    def __str__(self):
        return f'{self.employee.username} - {self.start_time} to {self.end_time}'

class TimeOffRequest(models.Model):
    STATUS_CHOICES = (
        ('pending', 'Pending'),
        ('approved', 'Approved'),
        ('denied', 'Denied'),
    )
    employee = models.ForeignKey(User, on_delete=models.CASCADE, related_name='time_off_requests')
    start_date = models.DateField()
    end_date = models.DateField()
    reason = models.TextField()
    status = models.CharField(max_length=10, choices=STATUS_CHOICES, default='pending')

    def __str__(self):
        return f'{self.employee.username} - {self.start_date} to {self.end_date} ({self.get_status_display()})'
