export type NotificationPlatform = 'feishu' | string;

export type NotificationSourceType = 'skill' | 'api' | 'system';

export interface NotificationTargetUser {
  bizUserId?: string;
  externalUserId?: string;
  openId?: string;
  unionId?: string;
  userKey?: string;
  chatId?: string;
  email?: string;
  mobile?: string;
  name?: string;
}

export interface NotificationSendRequest {
  platform: NotificationPlatform;
  message: string;
  title?: string;
  messageType?: string;
  mentionAll?: boolean;
  receiveId?: string;
  receiveIdType?: string;
  targetUser?: NotificationTargetUser;
  appId?: string;
  appSecret?: string;
  sourceType?: NotificationSourceType;
  sourceId?: string;
  sourceName?: string;
  metadata?: Record<string, any>;
}

export interface ResolvedNotificationRecipient {
  receiveId: string;
  receiveIdType: string;
  userSnapshot?: Record<string, any>;
}

export interface NotificationProviderSendParams {
  requestId: string;
  platform: NotificationPlatform;
  appId?: string;
  appSecret?: string;
  message: string;
  title?: string;
  messageType: string;
  mentionAll?: boolean;
  receiveId: string;
  receiveIdType: string;
  metadata?: Record<string, any>;
}

export interface NotificationProviderSendResult {
  success: boolean;
  platform: NotificationPlatform;
  externalMessageId?: string;
  requestId?: string;
  providerCode?: string | number;
  providerMessage?: string;
  providerPayload?: Record<string, any>;
  providerResponse?: Record<string, any>;
  errorMessage?: string;
}

export interface NotificationSendResult extends NotificationProviderSendResult {
  requestId: string;
  resolvedRecipient: ResolvedNotificationRecipient;
}

export interface NotificationBatchTarget {
  title?: string;
  message?: string;
  mentionAll?: boolean;
  receiveId?: string;
  receiveIdType?: string;
  targetUser?: NotificationTargetUser;
  sourceId?: string;
  metadata?: Record<string, any>;
}

export interface NotificationBatchSendRequest {
  platform: NotificationPlatform;
  title?: string;
  message?: string;
  messageType?: string;
  mentionAll?: boolean;
  targets: NotificationBatchTarget[];
  appId?: string;
  appSecret?: string;
  sourceType?: NotificationSourceType;
  sourceName?: string;
  metadata?: Record<string, any>;
}

export interface NotificationBatchSendResult {
  success: boolean;
  total: number;
  successCount: number;
  failCount: number;
  items: Array<NotificationSendResult & { index: number }>;
}

export interface NotificationProvider {
  readonly platform: NotificationPlatform;
  send(
    params: NotificationProviderSendParams
  ): Promise<NotificationProviderSendResult>;
}
