/**
 * User Service - Mirror backend user endpoints
 */
import { apiClient } from '../client';
import { UserResponse, UserUpdate } from '../types/auth';
import { AdminDeleteRequest, AdminDeleteResponse } from '../types/user';

export class UserService {
  private readonly baseUrl = '/users';

  async getCurrentUser(): Promise<UserResponse> {
    // Get current user ID from auth store
    const authStore = useAuthStore.getState();
    const userId = authStore.user?.id;
    
    if (!userId) {
      throw new Error('No authenticated user found');
    }
    
    return apiClient.get<UserResponse>(`${this.baseUrl}/${userId}`);
  }

  async updateUser(userId: string, updateData: UserUpdate): Promise<UserResponse> {
    return apiClient.put<UserResponse>(`${this.baseUrl}/${userId}`, updateData);
  }

  async deleteUser(userId: string): Promise<{ message: string }> {
    return apiClient.delete<{ message: string }>(`${this.baseUrl}/${userId}`);
  }

  // Admin operations
  async adminDeleteUser(deleteRequest: AdminDeleteRequest): Promise<AdminDeleteResponse> {
    return apiClient.post<AdminDeleteResponse>(`${this.baseUrl}/admin/delete`, deleteRequest);
  }

  async getAllUsers(): Promise<UserResponse[]> {
    return apiClient.get<UserResponse[]>(`${this.baseUrl}/admin/all`);
  }

  async getUserById(userId: string): Promise<UserResponse> {
    return apiClient.get<UserResponse>(`${this.baseUrl}/admin/${userId}`);
  }

 async getUserActivity(userId: string): Promise<any> {
    return apiClient.get<any>(`/auth/users/${userId}/activity`);
  }
}

export const userService = new UserService();
