# payments/models.py

from django.db import models

class DarajaAPIConfiguration(models.Model):
    business_short_code = models.CharField(max_length=20)
    lipa_na_mpesa_online_passkey = models.CharField(max_length=100)
    consumer_key = models.CharField(max_length=100)
    consumer_secret = models.CharField(max_length=100)
    shortcode_type = models.CharField(max_length=50, choices=[('Till Number', 'Till Number'), ('Paybill', 'Paybill')])
    callback_url = models.URLField(max_length=200)
    environment = models.CharField(max_length=10, choices=[('sandbox', 'Sandbox'), ('production', 'Production')])

    def __str__(self):
        return f"{self.business_short_code} - {self.environment}"

class PaymentTransaction(models.Model):
    phone_number = models.CharField(max_length=15)
    amount = models.DecimalField(max_digits=10, decimal_places=2)
    transaction_id = models.CharField(max_length=100, blank=True, null=True)
    status = models.CharField(max_length=50, choices=[('pending', 'Pending'), ('success', 'Success'), ('failed', 'Failed')], default='pending')
    created_at = models.DateTimeField(auto_now_add=True)
    updated_at = models.DateTimeField(auto_now=True)

    def __str__(self):
        return f"{self.phone_number} - {self.amount}"
