import { apiFetch } from '../../../../lib/fetch/apiClient';
const isRecord = (value) => typeof value === 'object' && value !== null;
const normalizeCountValue = (value) => {
    const count = Number(value || 0);
    return Number.isFinite(count) && count > 0 ? Math.floor(count) : 0;
};
const normalizeCountByCodeMap = (raw) => Object.fromEntries(Object.entries(raw || {}).map(([code, count]) => [
    code,
    normalizeCountValue(typeof count === 'number' ? count : Number(count)),
]));
export const parseRequiredActionPayload = (payload) => {
    const counts = isRecord(payload) && isRecord(payload.counts) ? payload.counts : {};
    const countByCode = normalizeCountByCodeMap(counts);
    return { countByCode };
};
export const fetchRequiredActionData = async () => {
    try {
        const response = await apiFetch('/inapp-noti/required-action', {
            method: 'GET',
        });
        return parseRequiredActionPayload(response);
    }
    catch (_a) {
        return { countByCode: {} };
    }
};
//# sourceMappingURL=required-action-api.js.map