from django.contrib.postgres.fields import ArrayField
from django.core.validators import MinLengthValidator
from django.db import models


class OptimizationFeatures(models.Model):
    trace_id = models.CharField(max_length=36, primary_key=True, validators=[MinLengthValidator(36)])
    original_code = models.TextField(null=True, blank=True)
    user_id = models.TextField(null=True, blank=True)
    optimizations_raw = models.JSONField(null=True, blank=True)
    optimizations_post = models.JSONField(null=True, blank=True)
    explanations_raw = models.JSONField(null=True, blank=True)
    explanations_post = models.JSONField(null=True, blank=True)
    speedup_ratio = models.JSONField(null=True, blank=True)
    original_runtime = models.FloatField(null=True, blank=True)
    optimized_runtime = models.JSONField(null=True, blank=True)
    is_correct = models.JSONField(null=True, blank=True)
    generated_test = ArrayField(models.TextField(), null=True, blank=True)
    instrumented_generated_test = ArrayField(models.TextField(), null=True, blank=True)
    test_framework = models.CharField(max_length=32, null=True, blank=True)
    created_at = models.DateTimeField(auto_now_add=True, null=True, blank=True)
    aiservice_commit_id = models.CharField(max_length=50, null=True, blank=True)
    metadata = models.JSONField(null=True, blank=True)
    experiment_metadata = models.JSONField(null=True, blank=True)

    class Meta:
        managed = False
        db_table = "optimization_features"
