from django.db import models
from django.contrib.auth.models import User
from django.conf import settings 

class APILog(models.Model):
    user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, null=True, blank=True)
    client_id = models.IntegerField(default=0)
    endpoint = models.URLField()
    request_data = models.TextField()
    response_data = models.TextField()
    status_code = models.IntegerField()
    timestamp = models.DateTimeField(auto_now_add=True)

    def __str__(self):
        return f"{self.user} - {self.endpoint} - {self.timestamp}"




class PendingOrder(models.Model):
    order_id = models.CharField(max_length=255, unique=True)  # Order ID
    client_id = models.CharField(max_length=100, null=True, blank=True)
    amount = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)
    status = models.CharField(max_length=50, default='created')  # Pending status by default
    created_at = models.DateTimeField(auto_now_add=True)  # Timestamp of order creation
    updated_at = models.DateTimeField(auto_now=True)  # Timestamp of last update
    billing_cycle = models.IntegerField(default=1, help_text="Billing cycle in months: 1 (Monthly), 3 (Quarterly), 6 (Half-Yearly), 12 (Yearly)")
    invoice_id = models.CharField(max_length=255, blank=True, null=True)
    billing_from_date = models.DateField(null=True, blank=True)
    billing_to_date = models.DateField(null=True, blank=True)
    invoice_amount = models.DecimalField(max_digits=10, decimal_places=2, null=True, blank=True)

    def __str__(self):
        return f"Order ID: {self.order_id}, Client ID: {self.client_id}, Status: {self.status}"

    class Meta:
        verbose_name = 'Pending Order'
        verbose_name_plural = 'Pending Orders'