import { http } from './client';

export const authApi = {
  login: (data: { tenantCode: string; username: string; password: string }) =>
    http.post('/auth/login', data) as Promise<any>,
  me: () => http.get('/auth/me') as Promise<any>,
  changePassword: (data: { oldPassword: string; newPassword: string }) =>
    http.post('/auth/change-password', data) as Promise<any>,
};

export const dashboardApi = {
  summary: (params?: any) => http.get('/dashboard/summary', { params }) as Promise<any>,
};

export const regionApi = {
  tree: () => http.get('/regions/tree') as Promise<any>,
  create: (data: any) => http.post('/regions', data) as Promise<any>,
};

export const lampApi = {
  list: (params?: any) => http.get('/lamps', { params }) as Promise<any>,
  create: (data: any) => http.post('/lamps', data) as Promise<any>,
  syncIlc: () => http.post('/lamps/sync-ilc', undefined, { timeout: 180000 }) as Promise<any>,
  syncPlatform: (data: any) => http.post('/lamps/sync-platform', data, { timeout: 180000 }) as Promise<any>,
  update: (id: string, data: any) => http.patch(`/lamps/${id}`, data) as Promise<any>,
  remove: (id: string) => http.delete(`/lamps/${id}`) as Promise<any>,
};

export const alarmApi = {
  list: (params?: any) => http.get('/alarms', { params }) as Promise<any>,
  handle: (id: string, data: any) => http.patch(`/alarms/${id}/handle`, data) as Promise<any>,
};

export const mapApi = {
  points: (params?: any) => http.get('/map/points', { params }) as Promise<any>,
};

export const systemApi = {
  tenants: (params?: any) => http.get('/tenants', { params }) as Promise<any>,
  createTenant: (data: any) => http.post('/tenants', data) as Promise<any>,
  updateTenant: (id: string, data: any) => http.patch(`/tenants/${id}`, data) as Promise<any>,
  users: (params?: any) => http.get('/users', { params }) as Promise<any>,
  createUser: (data: any) => http.post('/users', data) as Promise<any>,
  roles: (params?: any) => http.get('/roles', { params }) as Promise<any>,
  permissions: () => http.get('/roles/permissions') as Promise<any>,
  createRole: (data: any) => http.post('/roles', data) as Promise<any>,
  updateRole: (id: string, data: any) => http.patch(`/roles/${id}`, data) as Promise<any>,
};
