// web/services/userSettingService.ts
import { apiClient } from './apiClient';
import { AppSettings } from '../types'; // Frontend AppSettings interface

// Assuming backend returns language, plus id, userId, createdAt, updatedAt
interface UserPersonalSettingResponse {
  id: string;
  userId: string;
  language: string;
  createdAt: Date;
  updatedAt: Date;
}

interface UserSettingResponse extends AppSettings {
  id: string;
  userId: string;
  createdAt: Date;
  updatedAt: Date;
}

export const userSettingService = {
  async get(_token: string): Promise<UserSettingResponse> {
    const { data } = await apiClient.get<UserSettingResponse>('/v1/admin/settings');
    return data;
  },

  async update(_token: string, settings: Partial<AppSettings>): Promise<UserSettingResponse> {
    const { data } = await apiClient.put<UserSettingResponse>('/v1/admin/settings', settings);
    return data;
  },

  async getPersonal(_token: string): Promise<UserPersonalSettingResponse> {
    const { data } = await apiClient.get<UserPersonalSettingResponse>('/users/settings');
    return data;
  },

  async updateLanguage(_token: string, language: string): Promise<UserPersonalSettingResponse> {
    const { data } = await apiClient.put<UserPersonalSettingResponse>('/users/settings/language', { language });
    return data;
  },

  // Unused legacy methods removed
};
