export type NotificationType =
  | 'SYSTEM'
  | 'MAINTENANCE'
  | 'FEATURE'
  | 'ANNOUNCEMENT'
  | 'BILLING'
  | 'SECURITY';

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

export type TargetType =
  | 'ALL'
  | 'SPECIFIC_TENANTS'
  | 'SPECIFIC_USERS'
  | 'BY_TENANT_TAG'
  | 'BY_PLAN'
  | 'BY_TENANT_STATUS'
  | 'BY_SEGMENT';

export type TagLogic = 'ANY' | 'ALL';

export interface NotificationItem {
  id: string;
  title: string;
  content: string;
  type: NotificationType;
  priority: NotificationPriority;
  targetType: TargetType;
  tenantIds?: string[];
  userIds?: string[];
  targetTagIds?: string[] | null;
  targetTagLogic?: TagLogic;
  targetPlans?: string[] | null;
  targetStatuses?: string[] | null;
  targetSegment?: string | null;
  channelKey?: string | null;
  imageUrl: string | null;
  linkUrl: string | null;
  requiresForceRead: boolean;
  isEnabled: boolean;
  publishedAt: string | null;
  expiresAt: string | null;
  createdBy: string | null;
  createdAt: string;
  updatedAt: string;
}

export interface NotificationListResult {
  items: NotificationItem[];
  total: number;
}

export interface CreateNotificationPayload {
  title: string;
  content: string;
  type: NotificationType;
  priority: NotificationPriority;
  targetType: TargetType;
  tenantIds?: string[];
  userIds?: string[];
  targetTagIds?: string[];
  targetTagLogic?: TagLogic;
  targetPlans?: string[];
  targetStatuses?: string[];
  targetSegment?: string | null;
  channelKey?: string | null;
  imageUrl?: string | null;
  linkUrl?: string | null;
  requiresForceRead: boolean;
  isEnabled: boolean;
  publishedAt?: string | null;
  expiresAt?: string | null;
}

export const NOTIFICATION_TYPE_OPTIONS: { value: NotificationType; label: string; color: string }[] = [
  { value: 'SYSTEM',       label: '系统通知',   color: 'bg-gray-100 text-gray-700' },
  { value: 'MAINTENANCE',  label: '维护通知',   color: 'bg-orange-100 text-orange-700' },
  { value: 'FEATURE',      label: '新功能',     color: 'bg-green-100 text-green-700' },
  { value: 'ANNOUNCEMENT', label: '公告',       color: 'bg-blue-100 text-blue-700' },
  { value: 'BILLING',      label: '账单通知',   color: 'bg-purple-100 text-purple-700' },
  { value: 'SECURITY',     label: '安全通知',   color: 'bg-red-100 text-red-700' },
];

export const NOTIFICATION_PRIORITY_OPTIONS: { value: NotificationPriority; label: string }[] = [
  { value: 'LOW',    label: '低' },
  { value: 'NORMAL', label: '普通' },
  { value: 'HIGH',   label: '高' },
  { value: 'URGENT', label: '紧急' },
];

export const TARGET_TYPE_OPTIONS: { value: TargetType; label: string; desc: string }[] = [
  { value: 'ALL',              label: '全部租户',    desc: '发送给平台所有租户' },
  { value: 'SPECIFIC_TENANTS', label: '指定租户',    desc: '手动输入租户 ID 列表' },
  { value: 'SPECIFIC_USERS',   label: '指定用户',    desc: '手动输入用户 ID 列表' },
  { value: 'BY_TENANT_TAG',    label: '按标签',      desc: '推送给拥有指定标签的租户' },
  { value: 'BY_PLAN',          label: '按套餐',      desc: '推送给特定订阅套餐的租户' },
  { value: 'BY_TENANT_STATUS', label: '按租户状态',  desc: '推送给特定状态的租户' },
  { value: 'BY_SEGMENT',       label: '按人群包',    desc: '推送给预定义分群的租户' },
];

export const PLAN_OPTIONS = ['free', 'pro', 'enterprise'];
export const STATUS_OPTIONS = ['active', 'suspended', 'trial', 'expired'];
