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

class Application(models.Model):
    STATUS_CHOICES = [
        ('pending', '待查看'),
        ('viewed', '已查看'),
        ('interviewing', '面试中'),
        ('hired', '已录用'),
        ('rejected', '已拒绝'),
    ]
    job = models.ForeignKey('jobs.Job', on_delete=models.CASCADE, related_name='applications')
    applicant = models.ForeignKey(
        settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name='applications'
    )
    resume_snapshot = models.JSONField(verbose_name='简历快照')
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
    note = models.TextField(blank=True, verbose_name='HR备注')
    applied_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    class Meta:
        unique_together = [['job', 'applicant']]
        ordering = ['-applied_at']
        verbose_name = '投递记录'
