import { apiClient } from './client';

// 后端统一响应格式
interface ApiResponse<T> {
  success: boolean;
  data: T;
  timestamp: string;
}

interface LoginData {
  token: string;
  admin: { id: string; username: string; name: string; role: string };
}

interface ProfileData {
  id: string;
  username: string;
  role: string;
}

export const authApi = {
  login: (username: string, password: string) =>
    apiClient.post<ApiResponse<LoginData>>('/auth/login', {
      username,
      password,
    }),

  getProfile: () =>
    apiClient.get<ApiResponse<ProfileData>>('/auth/profile'),

  changePassword: (oldPassword: string, newPassword: string) =>
    apiClient.post('/auth/change-password', { oldPassword, newPassword }),
};
