import request from '@/utils/request';

export function loginByPassword(username: string, password: string) {
  return request.post('/api/admin/auth/login', { username, password });
}

export function getAdminProfile() {
  return request.get('/api/admin/auth/profile');
}

export function changeAdminPassword(data: { oldPassword: string; newPassword: string }) {
  return request.put('/api/admin/auth/password', data);
}

// 商家管理
export function getMerchantList(params: any) {
  return request.get('/api/admin/merchants', { params });
}

export function getMerchantDetail(id: number) {
  return request.get(`/api/admin/merchants/${id}`);
}

export function approveMerchant(id: number) {
  return request.put(`/api/admin/merchants/${id}/approve`);
}

export function rejectMerchant(id: number, reason: string) {
  return request.put(`/api/admin/merchants/${id}/reject`, { reason });
}

export function freezeMerchant(id: number) {
  return request.put(`/api/admin/merchants/${id}/freeze`);
}

export function unfreezeMerchant(id: number) {
  return request.put(`/api/admin/merchants/${id}/unfreeze`);
}

// 用户管理
export function getUserList(params: any) {
  return request.get('/api/admin/users', { params });
}

export function freezeUser(id: number) {
  return request.put(`/api/admin/users/${id}/freeze`);
}

export function unfreezeUser(id: number) {
  return request.put(`/api/admin/users/${id}/unfreeze`);
}

// 订单管理
export function getOrderList(params: any) {
  return request.get('/api/admin/orders', { params });
}

export function getOrderDetail(id: number) {
  return request.get(`/api/admin/orders/${id}`);
}

// 统计数据
export function getPlatformStatistics() {
  return request.get('/api/admin/finance/reports/overview');
}

export function getOrderTrend(params: { startDate: string; endDate: string }) {
  return request.get('/api/admin/finance/reports/trend', { params });
}
