"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.makeUFGClient = exports.defaultResourceCache = void 0;
const logger_1 = require("@applitools/logger");
const requests_1 = require("./server/requests");
const create_render_target_1 = require("./create-render-target");
const get_actual_environment_1 = require("./get-actual-environment");
const render_1 = require("./render");
const process_resources_1 = require("./resources/process-resources");
const fetch_resource_1 = require("./resources/fetch-resource");
const upload_resource_1 = require("./resources/upload-resource");
exports.defaultResourceCache = new Map();
function makeUFGClient({ settings, logger }) {
    var _a;
    const cache = !settings.asyncCache ? (_a = settings.syncCache) !== null && _a !== void 0 ? _a : exports.defaultResourceCache : undefined;
    logger = (0, logger_1.makeLogger)({ logger, format: { label: 'ufg-client' } });
    const requests = (0, requests_1.makeUFGRequests)({ settings, logger });
    const fetchResource = (0, fetch_resource_1.makeFetchResource)({
        concurrency: settings.fetchConcurrency,
        tunnelIds: settings.tunnelIds,
        accessToken: settings.accessToken,
        eyesServerUrl: settings.eyesServerUrl,
        apiKey: settings.apiKey,
        logger,
    });
    const uploadResource = (0, upload_resource_1.makeUploadResource)({ requests, logger });
    const processResources = (0, process_resources_1.makeProcessResources)({
        fetchResource,
        cache,
        asyncCache: settings.asyncCache,
        uploadResource,
        logger,
    });
    return {
        createRenderTarget: (0, create_render_target_1.makeCreateRenderTarget)({ processResources, logger }),
        render: (0, render_1.makeRender)({ requests, logger }),
        getActualEnvironment: (0, get_actual_environment_1.makeGetActualEnvironment)({ requests, logger }),
        getChromeEmulationDevices: requests.getChromeEmulationDevices,
        getAndroidDevices: requests.getAndroidDevices,
        getIOSDevices: requests.getIOSDevices,
        getCachedResourceUrls: () => (cache ? Array.from(cache.keys()) : []),
    };
}
exports.makeUFGClient = makeUFGClient;
