import { httpClient } from '@/services/http/client';
import {
  ConstantsApiResponse,
  TransformedConstants,
} from '@/types/api/constants/constants';
import { transformConstants } from '@/lib/helper';

class ConstantsApiService {
  async fetchConstants(): Promise<ConstantsApiResponse | undefined> {
    try {
      const response = await httpClient<ConstantsApiResponse>('/constants');
      return response;
    } catch {
      return undefined;
    }
  }

  async fetchTransformedConstants(): Promise<TransformedConstants | undefined> {
    const data = await this.fetchConstants();
    if (!data) return undefined;
    return transformConstants(data);
  }
}

export const ConstantsApi = new ConstantsApiService();
