export type NotificationChannel = 'in_app' | 'email' | 'line' | 'webhook';
export type NotificationEventStatus = 'pending' | 'processed' | 'failed';
export type NotificationStatus = 'unread' | 'read' | 'archived';
export type NotificationSeverity = 'info' | 'success' | 'warning' | 'error';

export type NotificationTemplateRecord = {
  id: string;
  organizationId: string;
  eventType: string;
  channel: NotificationChannel;
  titleTemplate: string;
  bodyTemplate: string;
  linkTemplate: string | null;
  isActive: boolean;
  metadata: Record<string, unknown> | null;
  createdAt: string;
  updatedAt: string;
  deletedAt: string | null;
  createdBy: string;
  updatedBy: string;
};

export type NotificationEventRecord = {
  id: string;
  organizationId: string;
  eventType: string;
  entityType: string;
  entityId: string;
  actorUserId: string | null;
  payload: Record<string, unknown> | null;
  dedupeKey: string | null;
  status: NotificationEventStatus;
  lastError: string | null;
  publishedAt: string;
  processedAt: string | null;
  createdAt: string;
  updatedAt: string;
};

export type AppNotificationRecord = {
  id: string;
  organizationId: string;
  recipientUserId: string;
  eventId: string;
  title: string;
  body: string;
  linkUrl: string | null;
  severity: NotificationSeverity;
  status: NotificationStatus;
  readAt: string | null;
  archivedAt: string | null;
  metadata: Record<string, unknown> | null;
  createdAt: string;
  updatedAt: string;
};

export type NotificationRecipientType =
  | 'explicit_user'
  | 'approval_current_step_approvers'
  | 'approval_requester'
  | 'approval_previous_actor'
  | 'entity_owner'
  | 'sales_owner';

export type NotificationRecipientTarget = {
  type: NotificationRecipientType;
  userIds?: string[];
  excludeActor?: boolean;
};

export type PublishNotificationEventInput = {
  organizationId: string;
  eventType: string;
  entityType: string;
  entityId: string;
  actorUserId?: string | null;
  payload?: Record<string, unknown>;
  dedupeKey?: string;
};

export type NotificationListFilters = {
  page?: number;
  limit?: number;
  status?: NotificationStatus | 'all';
};
