import type { AdminReportsOverviewDto } from '@/api/generated/models' import { createServiceError, errorResult, handleServiceError, type ServiceCallOptions, type ServiceResult, shouldBubbleErrorToParent, successResult, } from '@/services/errorHandler' import { unwrapApiData } from '@/services/apiResponse' import { getAdminReports } from '@/api/generated/admin-reports/admin-reports' export type AdminReportsOverview = AdminReportsOverviewDto const adminReportsApi = getAdminReports() export const GET_ADMIN_REPORTS_OVERVIEW = async (options?: ServiceCallOptions): Promise> => { try { const res = await adminReportsApi.adminReportsControllerGetOverview() const payload = res.data if (!payload.success) { throw createServiceError(payload.message || 'دریافت گزارش‌ها ناموفق بود') } const overview = unwrapApiData(payload) if (!overview) { throw createServiceError('پاسخ نامعتبر از سرور') } return successResult(overview) } catch (error) { const normalizedError = handleServiceError(error, options) if (shouldBubbleErrorToParent(options)) { throw normalizedError } return errorResult(normalizedError) } }