from django.conf import settings
from django.db import models

MODULE_CHOICES = [
    ('applications',  'Applications'),
    ('students',      'Students'),
    ('payments',      'Payments'),
    ('courses',       'Courses'),
    ('programs',      'Programs'),
    ('staff',         'Staff'),
    ('timetable',     'Timetable'),
    ('certificates',  'Certificates'),
    ('gallery',       'Gallery'),
    ('testimonials',  'Testimonials'),
    ('notifications', 'Notifications'),
    ('donations',     'Donations'),
    ('reports',       'Reports'),
    ('direct_enroll', 'Direct Enroll'),
]


class AdminModulePermission(models.Model):
    user = models.ForeignKey(
        settings.AUTH_USER_MODEL,
        on_delete=models.CASCADE,
        related_name='module_permissions',
        limit_choices_to={'role': 'admin'},
    )
    module = models.CharField(max_length=50, choices=MODULE_CHOICES)
    can_view = models.BooleanField(default=True)
    can_edit = models.BooleanField(default=True)
    can_delete = models.BooleanField(default=True)

    class Meta:
        unique_together = [('user', 'module')]
        ordering = ['user__first_name', 'module']

    def __str__(self):
        return f'{self.user.get_full_name()} — {self.get_module_display()}'
