// ─── Notification Category / Priority / TaskStatus ──────────────────────────
// Mirror Prisma enums for use in frontend/shared code

export type NotificationCategory =
  | "NOTIFICATION"
  | "REMINDER"
  | "TASK"
  | "APPROVAL";

export type NotificationPriority = "LOW" | "NORMAL" | "HIGH" | "URGENT";

export type TaskStatus = "OPEN" | "IN_PROGRESS" | "DONE" | "DISMISSED";

// ─── Task Action Helpers ────────────────────────────────────────────────────

export interface TaskActionDef {
  action: string; // e.g. "approve_vacation"
  entityId: string; // e.g. vacation ID
}

/** Parse a taskAction string like "approve_vacation:clxyz123" */
export function parseTaskAction(taskAction: string): TaskActionDef | null {
  const idx = taskAction.indexOf(":");
  if (idx < 0) return null;
  return { action: taskAction.slice(0, idx), entityId: taskAction.slice(idx + 1) };
}

/** Build a taskAction string */
export function buildTaskAction(action: string, entityId: string): string {
  return `${action}:${entityId}`;
}

// ─── Notification Interface ─────────────────────────────────────────────────

export interface Notification {
  id: string;
  userId: string;
  type: string;
  title: string;
  body?: string | null;
  entityId?: string | null;
  entityType?: string | null;
  readAt?: Date | null;
  createdAt: Date;
  updatedAt?: Date;

  // Extended fields
  category?: NotificationCategory;
  priority?: NotificationPriority;
  link?: string | null;

  // Task fields
  taskStatus?: TaskStatus | null;
  taskAction?: string | null;
  assigneeId?: string | null;
  dueDate?: Date | null;
  completedAt?: Date | null;
  completedBy?: string | null;

  // Reminder fields
  remindAt?: Date | null;
  recurrence?: string | null;
  nextRemindAt?: Date | null;

  // Targeting
  sourceId?: string | null;
  senderId?: string | null;
  channel?: string;
}

// ─── Broadcast Interface ────────────────────────────────────────────────────

export interface NotificationBroadcast {
  id: string;
  senderId: string;
  title: string;
  body?: string | null;
  link?: string | null;
  category?: NotificationCategory;
  priority?: NotificationPriority;
  channel?: string;

  targetType: string; // "user" | "role" | "project" | "orgUnit" | "all"
  targetValue?: string | null;

  scheduledAt?: Date | null;
  sentAt?: Date | null;
  recipientCount?: number;

  createdAt: Date;
}
