from django.db import models
from django.utils import timezone

from fwd_api.models.Subscription import Subscription


class SubscriptionRequest(models.Model):
    id = models.AutoField(primary_key=True)
    pages: int = models.IntegerField()
    pages_left: int = models.IntegerField(default=1)
    doc_type: str = models.CharField(max_length=100)
    request_id = models.CharField(max_length=200)  # Change to request_id
    process_type = models.CharField(max_length=200)  # driver/id/invoice
    provider_code = models.CharField(max_length=200, default="Guest")  # Request source FWD/CTel
    predict_result = models.JSONField(null=True)
    feedback_result = models.JSONField(null=True)
    status = models.IntegerField()  # 1: Processing(Pending) 2: PredictCompleted 3: ReturnCompleted
    subscription = models.ForeignKey(Subscription, on_delete=models.CASCADE)
    created_at = models.DateTimeField(default=timezone.now, db_index=True)
    updated_at = models.DateTimeField(auto_now=True)
    S3_uploaded = models.BooleanField(default=False)
    is_test_request = models.BooleanField(default=False)
    S3_uploaded = models.BooleanField(default=False)

    preprocessing_time = models.FloatField(default=-1)
    ai_inference_start_time = models.FloatField(default=0)
    ai_inference_time = models.FloatField(default=0)
    cpu_percent = models.FloatField(default=-1)
    gpu_percent = models.FloatField(default=-1)
    used_memory = models.FloatField(default=-1)
    total_memory = models.FloatField(default=-1)
    gpu_stats = models.CharField(max_length=100, null=True)
    is_reviewed = models.BooleanField(default=False)
    is_bad_image_quality = models.BooleanField(default=False)
