/**
 * Platform API
 * API functions for platform-level operations (businesses, users, etc.)
 */

import apiClient from './client';

export interface PlatformBusiness {
  id: number;
  name: string;
  subdomain: string;
  tier: string;
  is_active: boolean;
  created_at: string;
  user_count: number;
}

export interface PlatformUser {
  id: number;
  email: string;
  username: string;
  name?: string;
  role?: string;
  is_active: boolean;
  is_staff: boolean;
  is_superuser: boolean;
  business: number | null;
  business_name?: string;
  business_subdomain?: string;
  date_joined: string;
  last_login?: string;
}

/**
 * Get all businesses (platform admin only)
 */
export const getBusinesses = async (): Promise<PlatformBusiness[]> => {
  const response = await apiClient.get<PlatformBusiness[]>('/api/platform/businesses/');
  return response.data;
};

/**
 * Get all users (platform admin only)
 */
export const getUsers = async (): Promise<PlatformUser[]> => {
  const response = await apiClient.get<PlatformUser[]>('/api/platform/users/');
  return response.data;
};

/**
 * Get users for a specific business
 */
export const getBusinessUsers = async (businessId: number): Promise<PlatformUser[]> => {
  const response = await apiClient.get<PlatformUser[]>(`/api/platform/users/?business=${businessId}`);
  return response.data;
};
