"use server";
import { prisma } from "@/lib/prisma";
import { revalidatePath } from "next/cache";

export async function getOrders() {
  return await prisma.order.findMany({
    orderBy: { createdAt: 'desc' },
    include: { items: true, payments: true, customer: true }
  });
}

export async function updateOrderStatus(id: string, status: string) {
  try {
    const order = await prisma.order.update({ where: { id }, data: { status: status as any } });
    revalidatePath("/admin/orders");
    return { success: true, order };
  } catch (error: any) {
    return { success: false, error: error.message };
  }
}
