import http from './http';

export const api = {
  login: (payload: { account: string; password: string }) => http.post('/auth/login', payload),
  register: (payload: { username: string; phone?: string; email?: string; password: string }) =>
    http.post('/auth/register', payload),
  me: () => http.get('/users/me'),

  notices: (params?: any) => http.get('/public/notices', { params }),
  noticesAdmin: (params?: any) => http.get('/notices', { params }),
  createNotice: (payload: any) => http.post('/notices', payload),
  updateNotice: (id: number, payload: any) => http.put(`/notices/${id}`, payload),
  deleteNotice: (id: number) => http.delete(`/notices/${id}`),

  pets: (params?: any) => http.get('/pets', { params }),
  createPet: (payload: any) => http.post('/pets', payload),
  updatePet: (id: number, payload: any) => http.put(`/pets/${id}`, payload),
  deletePet: (id: number) => http.delete(`/pets/${id}`),

  appointments: (params?: any) => http.get('/appointments', { params }),
  createAppointment: (payload: any) => http.post('/appointments', payload),
  adminAppointments: (params?: any) => http.get('/appointments/admin', { params }),
  updateAppointmentStatus: (id: number, status: string) => http.put(`/appointments/${id}/status`, null, { params: { status } }),

  visits: (params?: any) => http.get('/visits', { params }),
  createVisit: (payload: any) => http.post('/visits', payload),
  updateVisit: (id: number, payload: any) => http.put(`/visits/${id}`, payload),

  medicalRecords: (params?: any) => http.get('/medical-records', { params }),
  createMedicalRecord: (payload: any) => http.post('/medical-records', payload),
  updateMedicalRecord: (id: number, payload: any) => http.put(`/medical-records/${id}`, payload),
  deleteMedicalRecord: (id: number) => http.delete(`/medical-records/${id}`),

  prescriptions: (params?: any) => http.get('/prescriptions', { params }),
  createPrescription: (payload: any) => http.post('/prescriptions', payload),
  updatePrescription: (id: number, payload: any) => http.put(`/prescriptions/${id}`, payload),

  prescriptionItems: (params?: any) => http.get('/prescription-items', { params }),
  createPrescriptionItem: (payload: any) => http.post('/prescription-items', payload),
  updatePrescriptionItem: (id: number, payload: any) => http.put(`/prescription-items/${id}`, payload),
  deletePrescriptionItem: (id: number) => http.delete(`/prescription-items/${id}`),

  reports: (params?: any) => http.get('/reports', { params }),
  createReport: (payload: any) => http.post('/reports', payload),
  updateReport: (id: number, payload: any) => http.put(`/reports/${id}`, payload),
  deleteReport: (id: number) => http.delete(`/reports/${id}`),

  orders: (params?: any) => http.get('/orders', { params }),
  createOrder: (payload: any) => http.post('/orders', payload),
  updateOrder: (id: number, payload: any) => http.put(`/orders/${id}`, payload),
  createOrderFromPrescription: (prescriptionId: number) => http.post(`/orders/from-prescription/${prescriptionId}`),
  getOrderDetail: (id: number) => http.get(`/orders/${id}`),
  payOrder: (id: number, paymentMethod: string) => http.put(`/orders/${id}/pay`, null, { params: { paymentMethod } }),

  drugs: (params?: any) => http.get('/drugs', { params }),
  createDrug: (payload: any) => http.post('/drugs', payload),
  updateDrug: (id: number, payload: any) => http.put(`/drugs/${id}`, payload),
  deleteDrug: (id: number) => http.delete(`/drugs/${id}`),

  stockIn: (params?: any) => http.get('/stock-in', { params }),
  createStockIn: (payload: any) => http.post('/stock-in', payload),
  stockOut: (params?: any) => http.get('/stock-out', { params }),
  createStockOut: (payload: any) => http.post('/stock-out', payload),

  messages: (params?: any) => http.get('/messages/admin', { params }),
  createMessage: (payload: any) => http.post('/messages', payload),
  replyMessage: (id: number, payload: any) => http.put(`/messages/admin/${id}/reply`, payload),

  users: (params?: any) => http.get('/users', { params }),
  createUser: (payload: any) => http.post('/users', payload),
  updateUserStatus: (id: number, status: number) => http.put(`/users/${id}/status`, null, { params: { status } }),
  resetUserPassword: (id: number, newPassword: string) => http.put(`/users/${id}/reset-password`, null, { params: { newPassword } }),

  stats: () => http.get('/admin/stats'),
  statsTrends: (period?: string) => http.get('/admin/stats/trends', { params: { period } }),
  todayTodos: () => http.get('/admin/stats/today-todos'),
  statsRevenueReport: (params?: any) => http.get('/admin/stats/report/revenue', { params }),
  statsRevenueSources: (params?: any) => http.get('/admin/stats/report/revenue-sources', { params }),
  statsDrugSales: (params?: any) => http.get('/admin/stats/report/drug-sales', { params }),
  statsDoctorPerformance: (params?: any) => http.get('/admin/stats/report/doctor-performance', { params }),
  statsDepartmentPerformance: (params?: any) => http.get('/admin/stats/report/department-performance', { params }),
};
