import { 
  AdminDashboardStats, 
  ContentManagementData, 
  UserManagementData, 
  BookingManagementData,
  SupportTicket,
  AdminLog,
  AnalyticsData
} from '../types/admin';

export const mockDashboardStats: AdminDashboardStats = {
  totalUsers: 1247,
  activeSubscriptions: 892,
  monthlyRevenue: 45678,
  totalContent: 156,
  pendingTickets: 23,
  upcomingBookings: 8,
  userGrowth: {
    thisMonth: 89,
    lastMonth: 67,
    percentage: 32.8
  },
  revenueGrowth: {
    thisMonth: 45678,
    lastMonth: 38945,
    percentage: 17.3
  },
  contentStats: {
    episodes: 45,
    articles: 67,
    downloads: 23,
    courses: 21
  },
  engagementStats: {
    averageSessionTime: 1240, // seconds
    completionRate: 78.5,
    activeUsers: 567
  }
};

export const mockContentData: ContentManagementData = {
  episodes: [
    {
      id: 'ep-1',
      title: 'Ekskluzywny odcinek: Głęboka praca z oddechem',
      description: 'Specjalny odcinek poświęcony zaawansowanym technikom oddechowym.',
      audioUrl: '/audio/premium-episode-1.mp3',
      duration: 2700, // 45 minutes
      category: 'Medytacja',
      tags: ['oddech', 'medytacja', 'wrażliwość'],
      isPremium: true,
      requiredTier: 'CZUŁOŚĆ',
      isPublished: true,
      publishedAt: new Date('2024-01-15'),
      views: 1247,
      createdAt: new Date('2024-01-10'),
      updatedAt: new Date('2024-01-15')
    },
    {
      id: 'ep-2',
      title: 'Praca z emocjami dla wrażliwych kobiet',
      description: 'Odcinek o zdrowym przepracowywaniu trudnych emocji.',
      audioUrl: '/audio/episode-2.mp3',
      duration: 3120, // 52 minutes
      category: 'Emocje',
      tags: ['emocje', 'przepracowanie', 'zdrowie psychiczne'],
      isPremium: true,
      requiredTier: 'CZUŁOŚĆ',
      isPublished: true,
      publishedAt: new Date('2024-02-05'),
      views: 892,
      createdAt: new Date('2024-02-03'),
      updatedAt: new Date('2024-02-05')
    }
  ],
  articles: [
    {
      id: 'art-1',
      title: 'Jak budować zdrową relację z własną wrażliwością',
      content: 'Długi artykuł o wrażliwości...',
      excerpt: 'Praktyczny przewodnik po akceptacji i wykorzystaniu swojej wrażliwości jako siły.',
      slug: 'jak-budowac-zdrowa-relacje-z-wlasna-wrazliwoscia',
      category: 'Rozwój osobisty',
      tags: ['wrażliwość', 'samoakceptacja', 'rozwój'],
      isPremium: true,
      requiredTier: 'CZUŁOŚĆ',
      isPublished: true,
      publishedAt: new Date('2024-01-20'),
      seoTitle: 'Wrażliwość jako siła - praktyczny przewodnik',
      seoDescription: 'Dowiedz się, jak wykorzystać swoją wrażliwość jako siłę w codziennym życiu.',
      featuredImage: '/images/article-1.jpg',
      views: 2341,
      readingTime: 8,
      createdAt: new Date('2024-01-18'),
      updatedAt: new Date('2024-01-20')
    }
  ],
  downloads: [
    {
      id: 'dl-1',
      title: 'Przewodnik: 30 dni do lepszego snu',
      description: 'PDF z praktycznymi ćwiczeniami i technikami poprawiającymi jakość snu.',
      fileUrl: '/downloads/sleep-guide.pdf',
      fileSize: 2048576, // 2MB
      fileType: 'application/pdf',
      isPremium: true,
      requiredTier: 'CZUŁOŚĆ',
      downloadCount: 567,
      isActive: true,
      createdAt: new Date('2024-01-28'),
      updatedAt: new Date('2024-01-30')
    }
  ],
  products: [
    {
      id: 'prod-1',
      name: 'Kurs: Droga do wewnętrznej wolności',
      description: 'Kompleksowy kurs składający się z 8 modułów.',
      price: 299,
      currency: 'PLN',
      category: 'Kursy',
      type: 'course',
      isActive: true,
      images: ['/images/course-1.jpg', '/images/course-2.jpg'],
      createdAt: new Date('2024-01-28'),
      updatedAt: new Date('2024-02-01')
    }
  ]
};

export const mockUserData: UserManagementData[] = [
  {
    id: 'user-1',
    name: 'Anna Kowalska',
    email: 'anna@example.com',
    tier: 'CZUŁOŚĆ',
    subscriptionStatus: 'active',
    lastLogin: new Date('2024-01-15T10:30:00'),
    createdAt: new Date('2023-11-15'),
    totalSpent: 348,
    contentConsumed: 23,
    isActive: true
  },
  {
    id: 'user-2',
    name: 'Maria Nowak',
    email: 'maria@example.com',
    tier: 'WOLNOŚĆ',
    subscriptionStatus: 'active',
    lastLogin: new Date('2024-01-14T15:45:00'),
    createdAt: new Date('2023-10-20'),
    totalSpent: 897,
    contentConsumed: 45,
    isActive: true
  },
  {
    id: 'user-3',
    name: 'Katarzyna Wiśniewska',
    email: 'kasia@example.com',
    tier: 'ODDECH',
    subscriptionStatus: 'inactive',
    lastLogin: new Date('2024-01-10T09:15:00'),
    createdAt: new Date('2023-12-05'),
    totalSpent: 0,
    contentConsumed: 5,
    isActive: false
  }
];

export const mockBookingData: BookingManagementData[] = [
  {
    id: 'booking-1',
    userId: 'user-1',
    userName: 'Anna Kowalska',
    userEmail: 'anna@example.com',
    consultationType: 'Konsultacja Ayurvediczna',
    date: new Date('2024-01-20T14:00:00'),
    duration: 60,
    status: 'confirmed',
    notes: 'Pierwsza konsultacja, klientka zainteresowana pracą z oddechem',
    followUpRequired: true,
    createdAt: new Date('2024-01-15'),
    updatedAt: new Date('2024-01-15')
  },
  {
    id: 'booking-2',
    userId: 'user-2',
    userName: 'Maria Nowak',
    userEmail: 'maria@example.com',
    consultationType: 'Terapia głosowa',
    date: new Date('2024-01-22T16:00:00'),
    duration: 90,
    status: 'pending',
    notes: '',
    followUpRequired: false,
    createdAt: new Date('2024-01-16'),
    updatedAt: new Date('2024-01-16')
  }
];

export const mockSupportTickets: SupportTicket[] = [
  {
    id: 'ticket-1',
    userId: 'user-1',
    userEmail: 'anna@example.com',
    userTier: 'CZUŁOŚĆ',
    subject: 'Problem z dostępem do premium treści',
    description: 'Nie mogę uzyskać dostępu do ekskluzywnych odcinków mimo aktywnej subskrypcji.',
    status: 'in_progress',
    priority: 'high',
    category: 'technical',
    assignedTo: 'admin-1',
    messages: [
      {
        id: 'msg-1',
        ticketId: 'ticket-1',
        senderId: 'user-1',
        senderName: 'Anna Kowalska',
        senderType: 'user',
        message: 'Nie mogę uzyskać dostępu do ekskluzywnych odcinków mimo aktywnej subskrypcji.',
        timestamp: new Date('2024-01-15T10:00:00')
      },
      {
        id: 'msg-2',
        ticketId: 'ticket-1',
        senderId: 'admin-1',
        senderName: 'Arla Admin',
        senderType: 'admin',
        message: 'Sprawdzę to dla Ciebie. Czy możesz podać więcej szczegółów?',
        timestamp: new Date('2024-01-15T11:30:00')
      }
    ],
    createdAt: new Date('2024-01-15T10:00:00'),
    updatedAt: new Date('2024-01-15T11:30:00')
  }
];

export const mockAdminLogs: AdminLog[] = [
  {
    id: 'log-1',
    adminId: 'admin-1',
    adminName: 'Arla Admin',
    action: 'created_episode',
    details: 'Created new episode: "Ekskluzywny odcinek: Głęboka praca z oddechem"',
    resourceType: 'content',
    resourceId: 'ep-1',
    ipAddress: '192.168.1.100',
    userAgent: 'Mozilla/5.0...',
    timestamp: new Date('2024-01-15T14:30:00')
  },
  {
    id: 'log-2',
    adminId: 'admin-1',
    adminName: 'Arla Admin',
    action: 'updated_user_tier',
    details: 'Updated user tier from ODDECH to CZUŁOŚĆ for user@example.com',
    resourceType: 'user',
    resourceId: 'user-1',
    ipAddress: '192.168.1.100',
    userAgent: 'Mozilla/5.0...',
    timestamp: new Date('2024-01-14T16:45:00')
  }
];

export const mockAnalyticsData: AnalyticsData[] = [
  {
    id: 'analytics-1',
    date: new Date('2024-01-15'),
    metric: 'daily_revenue',
    value: 1234,
    category: 'revenue',
    breakdown: {
      'CZUŁOŚĆ': 890,
      'WOLNOŚĆ': 344
    },
    createdAt: new Date('2024-01-15T23:59:59')
  },
  {
    id: 'analytics-2',
    date: new Date('2024-01-15'),
    metric: 'new_users',
    value: 23,
    category: 'users',
    createdAt: new Date('2024-01-15T23:59:59')
  },
  {
    id: 'analytics-3',
    date: new Date('2024-01-15'),
    metric: 'content_views',
    value: 1247,
    category: 'engagement',
    breakdown: {
      'episodes': 567,
      'articles': 423,
      'downloads': 257
    },
    createdAt: new Date('2024-01-15T23:59:59')
  }
];

export const getAnalyticsForPeriod = (startDate: Date, endDate: Date, category?: string) => {
  return mockAnalyticsData.filter(data => {
    const dateMatch = data.date >= startDate && data.date <= endDate;
    const categoryMatch = category ? data.category === category : true;
    return dateMatch && categoryMatch;
  });
};

export const getRecentActivity = (limit: number = 10) => {
  return mockAdminLogs
    .sort((a, b) => b.timestamp.getTime() - a.timestamp.getTime())
    .slice(0, limit);
};

export const getPendingTickets = () => {
  return mockSupportTickets.filter(ticket => 
    ticket.status === 'open' || ticket.status === 'in_progress'
  );
};

export const getUpcomingBookings = () => {
  const now = new Date();
  return mockBookingData
    .filter(booking => booking.date > now && booking.status === 'confirmed')
    .sort((a, b) => a.date.getTime() - b.date.getTime());
}; 