from django.db import models

class Contact(models.Model):
    first_name = models.CharField(max_length=100, blank=True, null=True)
    last_name = models.CharField(max_length=100, blank=True, null=True)
    address = models.CharField(max_length=255, blank=True, null=True)
    city = models.CharField(max_length=100, blank=True, null=True)
    state = models.CharField(max_length=100, blank=True, null=True)
    zip_code = models.CharField(max_length=20, blank=True, null=True)

    def __str__(self):
        return f"{self.first_name} {self.last_name}"

class SkipTraceJob(models.Model):
    STATUS_CHOICES = [
        ('pending', 'Pending'),
        ('in_progress', 'In Progress'),
        ('completed', 'Completed'),
        ('failed', 'Failed'),
    ]
    created_at = models.DateTimeField(auto_now_add=True)
    status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
    original_file_name = models.CharField(max_length=255)

    def __str__(self):
        return f"Job {self.id} - {self.original_file_name}"

class SkipTraceResult(models.Model):
    job = models.ForeignKey(SkipTraceJob, related_name='results', on_delete=models.CASCADE)
    contact = models.ForeignKey(Contact, related_name='skip_trace_results', on_delete=models.CASCADE)
    found_address = models.CharField(max_length=255, blank=True, null=True)
    found_phone = models.CharField(max_length=20, blank=True, null=True)
    # Add other fields that the skip tracing service might return
    is_found = models.BooleanField(default=False)
    raw_response = models.JSONField(blank=True, null=True)

    def __str__(self):
        return f"Result for {self.contact} in Job {self.job.id}"