import { createTRPCRouter, managerProcedure, protectedProcedure } from "../trpc.js";
import {
  AssignTaskInputSchema,
  CreateBroadcastInputSchema,
  CreateManagedNotificationInputSchema,
  CreateReminderInputSchema,
  CreateTaskInputSchema,
  ListBroadcastsInputSchema,
  ListNotificationTasksInputSchema,
  ListRemindersInputSchema,
  MarkNotificationReadInputSchema,
  NotificationIdInputSchema,
  NotificationListInputSchema,
  UpdateNotificationTaskStatusInputSchema,
  UpdateReminderInputSchema,
  assignTask,
  countUnreadNotifications,
  createBroadcast,
  createManagedNotification,
  createReminder,
  createTask,
  deleteNotification,
  deleteReminder,
  executeNotificationTaskAction,
  getBroadcastById,
  getNotificationTaskCounts,
  getNotificationTaskDetail,
  listBroadcasts,
  listNotificationTasks,
  listNotifications,
  listReminders,
  markNotificationsRead,
  updateNotificationTaskStatus,
  updateReminder,
} from "./notification-procedure-support.js";

export const notificationRouter = createTRPCRouter({
  list: protectedProcedure
    .input(NotificationListInputSchema)
    .query(({ ctx, input }) => listNotifications(ctx, input)),

  unreadCount: protectedProcedure
    .query(({ ctx }) => countUnreadNotifications(ctx)),

  markRead: protectedProcedure
    .input(MarkNotificationReadInputSchema)
    .mutation(({ ctx, input }) => markNotificationsRead(ctx, input)),

  create: managerProcedure
    .input(CreateManagedNotificationInputSchema)
    .mutation(({ ctx, input }) => createManagedNotification(ctx, input)),

  listTasks: protectedProcedure
    .input(ListNotificationTasksInputSchema)
    .query(({ ctx, input }) => listNotificationTasks(ctx, input)),

  taskCounts: protectedProcedure
    .query(({ ctx }) => getNotificationTaskCounts(ctx)),

  getTaskDetail: protectedProcedure
    .input(NotificationIdInputSchema)
    .query(({ ctx, input }) => getNotificationTaskDetail(ctx, input)),

  updateTaskStatus: protectedProcedure
    .input(UpdateNotificationTaskStatusInputSchema)
    .mutation(({ ctx, input }) => updateNotificationTaskStatus(ctx, input)),

  executeTaskAction: protectedProcedure
    .input(NotificationIdInputSchema)
    .mutation(({ ctx, input }) => executeNotificationTaskAction(ctx, input)),

  createReminder: protectedProcedure
    .input(CreateReminderInputSchema)
    .mutation(({ ctx, input }) => createReminder(ctx, input)),

  updateReminder: protectedProcedure
    .input(UpdateReminderInputSchema)
    .mutation(({ ctx, input }) => updateReminder(ctx, input)),

  deleteReminder: protectedProcedure
    .input(NotificationIdInputSchema)
    .mutation(({ ctx, input }) => deleteReminder(ctx, input)),

  listReminders: protectedProcedure
    .input(ListRemindersInputSchema)
    .query(({ ctx, input }) => listReminders(ctx, input)),

  createBroadcast: managerProcedure
    .input(CreateBroadcastInputSchema)
    .mutation(({ ctx, input }) => createBroadcast(ctx, input)),

  listBroadcasts: managerProcedure
    .input(ListBroadcastsInputSchema)
    .query(({ ctx, input }) => listBroadcasts(ctx, input)),

  getBroadcastById: managerProcedure
    .input(NotificationIdInputSchema)
    .query(({ ctx, input }) => getBroadcastById(ctx, input)),

  createTask: managerProcedure
    .input(CreateTaskInputSchema)
    .mutation(({ ctx, input }) => createTask(ctx, input)),

  assignTask: managerProcedure
    .input(AssignTaskInputSchema)
    .mutation(({ ctx, input }) => assignTask(ctx, input)),

  delete: protectedProcedure
    .input(NotificationIdInputSchema)
    .mutation(({ ctx, input }) => deleteNotification(ctx, input)),
});
