"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.fetchRequiredActionData = exports.parseRequiredActionPayload = void 0;
const apiClient_1 = require("../../../../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)),
]));
const parseRequiredActionPayload = (payload) => {
    const counts = isRecord(payload) && isRecord(payload.counts) ? payload.counts : {};
    const countByCode = normalizeCountByCodeMap(counts);
    return { countByCode };
};
exports.parseRequiredActionPayload = parseRequiredActionPayload;
const fetchRequiredActionData = async () => {
    try {
        const response = await (0, apiClient_1.apiFetch)('/inapp-noti/required-action', {
            method: 'GET',
        });
        return (0, exports.parseRequiredActionPayload)(response);
    }
    catch (_a) {
        return { countByCode: {} };
    }
};
exports.fetchRequiredActionData = fetchRequiredActionData;
//# sourceMappingURL=required-action-api.js.map