from django.shortcuts import render
from django.http import HttpResponse
    
from django.views.decorators.csrf import csrf_exempt
from django.http import JsonResponse
from project.utils.order_sync import process_woo_order
import json

# Create your views here.
def home(request):
    return HttpResponse("<h1>Welcome to Ua Bella Manager!</h1>")

@csrf_exempt
def woo_webhook(request):
    try:
        payload = json.loads(request.body)
    except json.JSONDecodeError:
        return JsonResponse({"success": False, "error": "Invalid JSON"}, status=400)

    if payload.get("status") == "completed":
        process_woo_order(payload)

    return JsonResponse 