"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.AdblockerRequest = void 0;
exports.default = loadTrackerDBEngine;
const adblocker_1 = require("@ghostery/adblocker");
Object.defineProperty(exports, "AdblockerRequest", { enumerable: true, get: function () { return adblocker_1.Request; } });
// eslint-disable-next-line @typescript-eslint/require-await
function loadTrackerDBEngine(engineBytes) {
    return __awaiter(this, void 0, void 0, function* () {
        const engine = adblocker_1.FiltersEngine.deserialize(engineBytes);
        return {
            ENGINE_VERSION: adblocker_1.ENGINE_VERSION,
            engine,
            matchUrl(requestArgs, getPatternMetadataParams = { getDomainMetadata: true }) {
                const params = Object.assign({}, requestArgs);
                if (params.type === undefined) {
                    params.type = 'xhr';
                }
                return engine.getPatternMetadata(adblocker_1.Request.fromRawDetails(params), getPatternMetadataParams);
            },
            matchDomain(domain) {
                if (!engine.metadata) {
                    return [];
                }
                return engine.metadata.fromDomain(domain);
            },
        };
    });
}
