import { api } from "@/lib/api";
import type { ApiEnvelope } from "@/types/api";
import type { Commande } from "@/types/commande";

export async function getCommandes(): Promise<Commande[]> {
  const { data } = await api.get<ApiEnvelope<Commande[]>>("/commandes");
  return data.data;
}

export async function getCommande(uid: string): Promise<Commande> {
  const { data } = await api.get<ApiEnvelope<Commande>>(`/commandes/${uid}`);
  return data.data;
}

export async function creerCommande(payload: {
  produit_id: number;
  quantite: number;
  note_client?: string;
}): Promise<Commande> {
  const { data } = await api.post<ApiEnvelope<Commande>>("/commandes", payload);
  return data.data;
}

export async function annulerCommande(uid: string): Promise<void> {
  await api.delete(`/commandes/${uid}`);
}
