'use server';
import { safeFetchApi } from '@/lib/fetch.api';
import { SurveyStatisticsData } from '../schemas/statistics';
import { SurveyStatisticsSchema } from '../schemas/statistics-schema';


export const getSurveysStatistics = async (): Promise<SurveyStatisticsData> => {

  const [error, data] = await safeFetchApi(
    SurveyStatisticsSchema,
    `surveys/statistics`,
    'GET',
  );

  if (error) {
    console.log(error);
    // console.log(error.details);
    throw new Error('Ocurrio un error');
  }

  if (!data) {
    throw new Error('No statistics data available');
  }

  return data?.data;
};

