"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createHeadersFactory = createHeadersFactory;
// Create headers factory function
function createHeadersFactory(args) {
    return async (base) => {
        const result = {};
        // Add static or function headers
        if (args?.headers) {
            if (typeof args.headers === 'function') {
                const functionResult = await args.headers();
                for (const key in functionResult) {
                    result[key] = functionResult[key];
                }
            }
            else {
                for (const key in args.headers) {
                    result[key] = args.headers[key];
                }
            }
        }
        // Add base headers
        if (base) {
            for (const key in base) {
                result[key] = base[key];
            }
        }
        // Add auth headers
        if (args?.secret) {
            result['x-hasura-admin-secret'] = args.secret;
        }
        else if (args?.accessToken) {
            result.authorization = args.accessToken.startsWith('Bearer ')
                ? args.accessToken
                : `Bearer ${args.accessToken}`;
        }
        if (args?.auditUserId) {
            result['x-hasura-audit-user-id'] = args.auditUserId;
        }
        return result;
    };
}
