from django.db import models

class Signal(models.Model):
    SIGNAL_CHOICES = [
        ('BUY', 'Buy'),
        ('SELL', 'Sell'),
        ('WAIT', 'Wait'),
    ]

    symbol = models.CharField(max_length=20)
    signal = models.CharField(max_length=4, choices=SIGNAL_CHOICES)
    timeframe = models.CharField(max_length=10)
    timestamp = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.symbol} - {self.signal} ({self.timeframe})"

class ConfidenceScore(models.Model):
    signal = models.OneToOneField(Signal, on_delete=models.CASCADE, related_name='confidence_score')
    score = models.FloatField()
    timestamp = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.signal} - {self.score}"

class Backtest(models.Model):
    symbol = models.CharField(max_length=20)
    start_date = models.DateTimeField()
    end_date = models.DateTimeField()
    profit_loss = models.FloatField()
    win_rate = models.FloatField()
    max_drawdown = models.FloatField()
    timestamp = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"Backtest for {self.symbol} from {self.start_date} to {self.end_date}"