from django.db import models

from .constants import ORDER_STATUS_CHOICES, PAYMENT_METHOD_CHOICES, PAYMENT_STATUS_CHOICES


class Order(models.Model):
    order_id = models.CharField(max_length=32, unique=True, db_index=True, blank=True)
    full_name = models.CharField(max_length=120)
    phone = models.CharField(max_length=10, db_index=True)
    whatsapp_number = models.CharField(max_length=10, blank=True)
    address = models.TextField()
    district = models.CharField(max_length=80)
    state = models.CharField(max_length=80)
    pincode = models.CharField(max_length=6)
    quantity = models.PositiveIntegerField(default=1)
    total_amount = models.PositiveIntegerField()
    payment_method = models.CharField(max_length=40, choices=PAYMENT_METHOD_CHOICES)
    payment_status = models.CharField(max_length=20, choices=PAYMENT_STATUS_CHOICES, default="Pending")
    order_status = models.CharField(max_length=20, choices=ORDER_STATUS_CHOICES, default="Pending")
    order_notes = models.TextField(blank=True)
    created_at = models.DateTimeField(auto_now_add=True)

    class Meta:
        ordering = ["-created_at"]

    def __str__(self):
        return f"{self.order_id} - {self.full_name}"
