import { apiClient } from '@/services/api/client';
import { Report } from '../types';

const MOCK_REPORTS: Report[] = [
  {
    id: 'r1',
    targetId: 'u3',
    targetType: 'user',
    targetName: 'Bot_User_99',
    reason: 'Spam',
    description: 'Posting same link in 50 channels.',
    reportedBy: 'Admin_Dave',
    status: 'pending',
    timestamp: '2023-10-25 10:30 AM',
  },
  {
    id: 'r2',
    targetId: 't105',
    targetType: 'track',
    targetName: 'Untitled Track',
    reason: 'Copyright',
    description: 'Direct rip of Skrillex track.',
    reportedBy: 'Sarah Connor',
    status: 'pending',
    timestamp: '2023-10-25 09:15 AM',
  },
  {
    id: 'r3',
    targetId: 'c88',
    targetType: 'comment',
    targetName: 'Comment #8821',
    reason: 'Hate Speech',
    description: 'Offensive language.',
    reportedBy: 'Cyber_Producer',
    status: 'reviewed',
    timestamp: '2023-10-24 04:20 PM',
  },
];

const MOCK_UPLOADS = [
  {
    id: 'u1',
    name: 'Bass_Drop.wav',
    user: 'Skrillex',
    size: '12MB',
    date: '5 mins ago',
  },
  {
    id: 'u2',
    name: 'Project_Alpha.zip',
    user: 'Deadmau5',
    size: '450MB',
    date: '12 mins ago',
  },
  {
    id: 'u3',
    name: 'Cover_Art.png',
    user: 'Grimes',
    size: '4MB',
    date: '20 mins ago',
  },
];

export const adminService = {
  getDashboardStats: async () => {
    await new Promise((resolve) => setTimeout(resolve, 500));
    return {
      totalUsers: 12450,
      monthlyRevenue: 45290,
      activeSessions: 1840,
      pendingReports: 14,
      trends: { users: 5.2, revenue: 12.8, sessions: -2.4, reports: 0 },
    };
  },

  getModerationQueue: async (status: string = 'pending') => {
    await new Promise((resolve) => setTimeout(resolve, 600));
    return MOCK_REPORTS.filter((r) => status === 'all' || r.status === status);
  },

  resolveReport: async (_id: string, _action: string) => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    return { success: true };
  },

  getRecentUploads: async () => {
    await new Promise((resolve) => setTimeout(resolve, 400));
    return MOCK_UPLOADS;
  },

  getAuditLogs: async (params: {
    page?: number;
    limit?: number;
    user_id?: string;
    action?: string;
  }) => {
    const response = await apiClient.get<{ logs: any[]; pagination: any }>(
      '/audit/logs',
      { params },
    );
    return response.data;
  },
};
