import { apiGet } from './client';

export interface DiagnosticsIMessageDb {
  available: boolean;
  error: string | null;
}

export interface DiagnosticsMailScriptingBridge {
  available: boolean;
  error: string | null;
}

export type AuthStatus = 'authorized' | 'denied' | 'notDetermined' | 'restricted';
export type PhotosAuthStatus = AuthStatus | 'limited';

export interface Diagnostics {
  fullDiskAccess: boolean;
  iMessageDb: DiagnosticsIMessageDb;
  mailScriptingBridge: DiagnosticsMailScriptingBridge;
  calendarAuth: AuthStatus;
  photosAuth: PhotosAuthStatus;
  contactsAuth: AuthStatus;
}

export type ActivityLevel = 'info' | 'success' | 'error' | 'warning';

export interface ActivityEntry {
  timestamp: string;
  level: ActivityLevel;
  message: string;
}

export async function fetchActivity(): Promise<ActivityEntry[]> {
  try {
    return await apiGet<ActivityEntry[]>('/api/activity');
  } catch (err) {
    throw err instanceof Error ? err : new Error('fetchActivity failed');
  }
}

export async function fetchDiagnostics(): Promise<Diagnostics> {
  try {
    return await apiGet<Diagnostics>('/api/diagnostics');
  } catch (err) {
    throw err instanceof Error ? err : new Error('fetchDiagnostics failed');
  }
}
