from django.db import models
from django.utils import timezone

class Letter(models.Model):
    LETTER_TYPE_CHOICES = [
        ('IN', 'Surat Masuk'),
        ('OUT', 'Surat Keluar'),
    ]
    
    type = models.CharField(max_length=3, choices=LETTER_TYPE_CHOICES, default='IN')
    subject = models.CharField(max_length=255)
    letter_number = models.CharField(max_length=100, unique=True)
    date = models.DateField(default=timezone.now)
    sender_receiver = models.CharField(max_length=255, help_text="Pengirim untuk Surat Masuk, Penerima untuk Surat Keluar")
    description = models.TextField(blank=True, null=True)
    file_attachment = models.FileField(upload_to='letters/', blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"[{self.get_type_display()}] {self.letter_number} - {self.subject}"

class Student(models.Model):
    GENDER_CHOICES = [
        ('M', 'Laki-laki'),
        ('F', 'Perempuan'),
    ]
    
    nisn = models.CharField(max_length=20, unique=True)
    full_name = models.CharField(max_length=255)
    gender = models.CharField(max_length=1, choices=GENDER_CHOICES)
    birth_place = models.CharField(max_length=100)
    birth_date = models.DateField()
    address = models.TextField()
    is_active = models.BooleanField(default=True)
    photo = models.ImageField(upload_to='students/', blank=True, null=True)
    created_at = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.nisn} - {self.full_name}"