import client from '../client';

export interface ServiceHealthStatus {
  name: string;
  status: string;
  message: string;
  response_ms: number | null;
}

export interface SystemHealthResp {
  services: ServiceHealthStatus[];
  checked_at: string;
}

export interface RoleCount {
  role: string;
  count: number;
}

export interface UserActivityResp {
  daily_active: number;
  weekly_active: number;
  monthly_active: number;
  total_registered: number;
  by_role: RoleCount[];
}

export interface ModuleStatusResp {
  name: string;
  display_name: string;
  description: string;
  active: boolean;
  entity_count: number | null;
  route_count: number | null;
}

export interface PointsActivityItem {
  id: string;
  user_name: string;
  detail: string;
  amount: string;
  type: string;
  created_at: string;
}

export interface ArticleStatsResp {
  published: number;
  draft: number;
  pending_review: number;
  rejected: number;
  total_views: number;
}

export const dashboardApi = {
  getSystemHealth: () =>
    client.get('/health/admin/system-health').then((r) => r.data.data as SystemHealthResp),

  getUserActivity: () =>
    client.get('/health/admin/user-activity').then((r) => r.data.data as UserActivityResp),

  getModuleStatus: () =>
    client.get('/health/admin/modules').then((r) => r.data.data as ModuleStatusResp[]),

  getPointsRecentActivity: () =>
    client.get('/health/points/recent-activity').then((r) => r.data.data as PointsActivityItem[]),

  getArticleStats: () =>
    client.get('/health/articles/stats').then((r) => r.data.data as ArticleStatsResp),
};
