import { apiClient } from './apiClient';

export const userService = {
  async changePassword(currentPassword: string, newPassword: string): Promise<{ message: string }> {
    const { data } = await apiClient.put('/users/password', {
      currentPassword,
      newPassword,
    });
    return data;
  },

  async getUsers(): Promise<any[]> {
    const { data } = await apiClient.get('/users');
    return data;
  },

  async updateUser(userId: string, isAdmin: boolean): Promise<{ message: string }> {
    const { data } = await apiClient.put(`/users/${userId}`, {
      isAdmin,
    });
    return data;
  },

  async updateUserInfo(userId: string, userData: { isAdmin?: boolean; role?: string; password?: string }): Promise<{ message: string }> {
    const { data } = await apiClient.put(`/users/${userId}`, userData);
    return data;
  },

  async deleteUser(userId: string): Promise<{ message: string }> {
    const { data } = await apiClient.delete(`/users/${userId}`);
    return data;
  },

  async createUser(username: string, password: string, role?: string): Promise<{ message: string }> {
    const { data } = await apiClient.post('/users', {
      username,
      password,
      role,
    });
    return data;
  },
};
