# encryption_utils.py
from cryptography.fernet import Fernet
from django.conf import settings
from base64 import urlsafe_b64encode

class EncryptionUtils:
    def __init__(self):
        # SECRET_KEY ko 32 bytes bana kar base64 encode karo
        key_bytes = settings.SECRET_KEY.encode()[:32]
        key = urlsafe_b64encode(key_bytes.ljust(32, b'\0'))
        self.f = Fernet(key)

    def encrypt(self, data):
        return self.f.encrypt(data.encode()).decode()

    def decrypt(self, data):
        return self.f.decrypt(data.encode()).decode()


def get_fernet():
    # Same logic yaha bhi use kare
    key_bytes = settings.SECRET_KEY.encode()[:32]
    key = urlsafe_b64encode(key_bytes.ljust(32, b'\0'))
    return Fernet(key)
