import { prisma } from "../../config/prisma";
import { NotificationChannel, NotificationStatus } from "@prisma/client";

export async function createNotification(data: {
  userId: string;
  channel: NotificationChannel;
  title: string;
  message: string;
}) {
  return prisma.notification.create({
    data: {
      userId: data.userId,
      channel: data.channel,
      title: data.title,
      message: data.message,
      status: NotificationStatus.QUEUED,
    },
  });
}

export async function markAsSent(id: string) {
  return prisma.notification.update({
    where: { id },
    data: { status: "SENT", sentAt: new Date() },
  });
}

export async function markAsFailed(id: string) {
  return prisma.notification.update({
    where: { id },
    data: { status: "FAILED" },
  });
}

export async function getUserContact(userId: string) {
  return prisma.user.findUnique({
    where: { id: userId },
    select: { id: true, name: true, email: true },
  });
}
