export interface DashboardStats {
  totalRevenue: number;
  revenueChange: number;
  activeSubscriptions: number;
  subscriptionChange: number;
  pendingPayments: number;
  pendingAmount: number;
  avgRevenuePerUser: number;
  avgChange: number;
}

export interface Notification {
  id: string;
  type: 'subscription_expiring' | 'payment_success' | 'server_issue' | 'new_user' | 'support_ticket';
  title: string;
  message: string;
  timestamp: string;
  read: boolean;
  priority: 'low' | 'medium' | 'high';
  userId?: string;
  actionUrl?: string;
}

export const mockNotifications: Notification[] = [
  {
    id: '1',
    type: 'subscription_expiring',
    title: 'اشتراک در حال انقضا',
    message: '15 کاربر اشتراکشان تا 3 روز دیگر منقضی می‌شود',
    timestamp: '10 دقیقه پیش',
    read: false,
    priority: 'high',
    actionUrl: '/subscriptions'
  },
  {
    id: '2',
    type: 'payment_success',
    title: 'پرداخت موفق',
    message: 'علی محمدی مبلغ 300,000 تومان پرداخت کرد',
    timestamp: '25 دقیقه پیش',
    read: false,
    priority: 'medium',
    userId: '12',
    actionUrl: '/financial'
  },
  {
    id: '3',
    type: 'server_issue',
    title: 'مشکل سرور',
    message: 'سرور آلمان 1 - پینگ بالا (>200ms)',
    timestamp: '1 ساعت پیش',
    read: true,
    priority: 'high',
    actionUrl: '/servers'
  },
  {
    id: '4',
    type: 'new_user',
    title: 'کاربر جدید',
    message: '5 کاربر جدید امروز ثبت‌نام کردند',
    timestamp: '2 ساعت پیش',
    read: true,
    priority: 'low',
    actionUrl: '/users'
  },
  {
    id: '5',
    type: 'support_ticket',
    title: 'تیکت جدید',
    message: 'محمد رضایی تیکت پشتیبانی ارسال کرد',
    timestamp: '3 ساعت پیش',
    read: true,
    priority: 'medium',
    userId: '45',
    actionUrl: '/tickets'
  }
];

export const getDashboardStats = (): DashboardStats => {
  return {
    totalRevenue: 45780000,
    revenueChange: 12.5,
    activeSubscriptions: 342,
    subscriptionChange: 8.2,
    pendingPayments: 15,
    pendingAmount: 3450000,
    avgRevenuePerUser: 133800,
    avgChange: -2.1
  };
};

export const getNotifications = (limit?: number): Notification[] => {
  return limit ? mockNotifications.slice(0, limit) : mockNotifications;
};

export const getUnreadNotificationsCount = (): number => {
  return mockNotifications.filter(n => !n.read).length;
};

export const markNotificationAsRead = (id: string): void => {
  const notification = mockNotifications.find(n => n.id === id);
  if (notification) {
    notification.read = true;
  }
};

export const markAllNotificationsAsRead = (): void => {
  mockNotifications.forEach(n => n.read = true);
};
