// ---------------------------------------------------------------------------
// Users API client  (client-side)
// ---------------------------------------------------------------------------

import { apiFetch } from './client';

// ---------------------------------------------------------------------------
// Response shapes
// TODO: import from @/lib/types once the shared types package is finalised
// ---------------------------------------------------------------------------

export interface UserResponse {
  id: number;
  username: string;
  email: string;
  first_name: string;
  last_name: string;
}

export interface UserProfileResponse {
  id: number;
  user_id: number;
  username: string;
  first_name: string;
  last_name: string;
  profile_image_url?: string;
}

export interface UserListResponse {
  count: number;
  results: UserResponse[];
}

export interface ProfileListResponse {
  count: number;
  results: UserProfileResponse[];
}

// ---------------------------------------------------------------------------
// API functions
// ---------------------------------------------------------------------------

/**
 * List users who share residences with the current user.
 */
export function listUsers(): Promise<UserListResponse> {
  return apiFetch<UserListResponse>('/users/');
}

/**
 * Get a user by ID (must share a residence with the current user).
 */
export function getUser(id: number): Promise<UserResponse> {
  return apiFetch<UserResponse>(`/users/${id}/`);
}

/**
 * List profiles of users in shared residences.
 */
export function listProfiles(): Promise<ProfileListResponse> {
  return apiFetch<ProfileListResponse>('/users/profiles/');
}
