import { usePrisma } from "../utils/prisma";

type Emotion = "stress" | "sadness" | "anger" | "empty" | "boredom" | "other";

export async function getRecentUrgeLogs(userId: string, limit = 20) {
  const db = usePrisma();
  return db.urgeLog.findMany({
    where: { userId },
    orderBy: { timestamp: "desc" },
    take: limit,
    select: {
      id: true,
      timestamp: true,
      emotion: true,
      wasOvercome: true,
      breathingDone: true,
    },
  });
}

export async function createUrgeLog(
  userId: string,
  emotion: Emotion,
  wasOvercome: boolean,
  breathingDone: boolean,
) {
  const db = usePrisma();
  return db.urgeLog.create({
    data: { userId, emotion, wasOvercome, breathingDone },
    select: {
      id: true,
      timestamp: true,
      emotion: true,
      wasOvercome: true,
      breathingDone: true,
    },
  });
}

export async function deleteUserUrgeLogs(userId: string) {
  const db = usePrisma();
  return db.urgeLog.deleteMany({ where: { userId } });
}
