"""
Django Test Models for Storm Logger 2.0
Test models for Django integration testing
"""

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

from storm_logger import get_logger

logger = get_logger(__name__)


class TestModel(models.Model):
    """Test model for Storm Logger testing."""
    
    name = models.CharField(max_length=100)
    value = models.IntegerField(default=0)
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)
    
    class Meta:
        app_label = "test_app"
    
    def save(self, *args, **kwargs):
        """Override save to test logging."""
        logger.info(f"Saving TestModel: {self.name}")
        logger.business_metric("model_saves", 1)
        super().save(*args, **kwargs)
        logger.info(f"TestModel saved: {self.name} (ID: {self.id})")
    
    def delete(self, *args, **kwargs):
        """Override delete to test logging."""
        logger.info(f"Deleting TestModel: {self.name}")
        logger.business_metric("model_deletes", 1)
        super().delete(*args, **kwargs)
        logger.info(f"TestModel deleted: {self.name}")
    
    def __str__(self):
        return f"TestModel(name={self.name}, value={self.value})"


class UserProfile(models.Model):
    """User profile model for testing."""
    
    user = models.OneToOneField(User, on_delete=models.CASCADE)
    bio = models.TextField(blank=True)
    birth_date = models.DateField(null=True, blank=True)
    location = models.CharField(max_length=100, blank=True)
    
    class Meta:
        app_label = "test_app"
    
    def __str__(self):
        return f"UserProfile(user={self.user.username})"


class BusinessMetric(models.Model):
    """Business metric model for testing."""
    
    name = models.CharField(max_length=100)
    value = models.FloatField()
    timestamp = models.DateTimeField(auto_now_add=True)
    context = models.JSONField(default=dict)
    
    class Meta:
        app_label = "test_app"
    
    def __str__(self):
        return f"BusinessMetric(name={self.name}, value={self.value})"