import { api } from './api';

interface AppSetting {
  key: string;
  value: any;
  updated_at: string;
}

interface ApiResponse<T> {
  success: boolean;
  data: T;
}

export const settingsApi = {
  getAll: () => api.get<ApiResponse<AppSetting[]>>('/api/admin/settings').then(r => r.data.data),
  get: (key: string) => api.get<ApiResponse<AppSetting>>(`/api/admin/settings/${key}`).then(r => r.data.data),
  update: (key: string, value: any) => api.put<ApiResponse<AppSetting>>(`/api/admin/settings/${key}`, { value }).then(r => r.data.data),
};

export const preferencesApi = {
  get: () => api.get<{ success: boolean; data: Record<string, any> }>('/api/settings/preferences').then(r => r.data.data),
  update: (prefs: Record<string, any>) => api.put('/api/settings/preferences', prefs).then(r => r.data),
};
