// Copyright 2024 Adobe. All rights reserved.
// This file is licensed to you under the Apache License,
// Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
// or the MIT license (http://opensource.org/licenses/MIT),
// at your option.
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());
    });
};
import { getNeonBinary } from "./binary.js";
export class Reader {
    constructor(reader) {
        this.reader = reader;
    }
    json() {
        return JSON.parse(getNeonBinary().readerJson.call(this.reader));
    }
    remoteUrl() {
        return getNeonBinary().readerRemoteUrl.call(this.reader);
    }
    isEmbedded() {
        return getNeonBinary().readerIsEmbedded.call(this.reader);
    }
    resourceToAsset(uri, asset) {
        return __awaiter(this, void 0, void 0, function* () {
            return getNeonBinary().readerResourceToAsset.call(this.reader, uri, asset);
        });
    }
    static fromAsset(asset, settings) {
        return __awaiter(this, void 0, void 0, function* () {
            const settingsStr = settings ? (typeof settings === 'string' ? settings : JSON.stringify(settings)) : undefined;
            const reader = yield getNeonBinary().readerFromAsset(asset, settingsStr);
            return reader ? new Reader(reader) : null;
        });
    }
    static fromManifestDataAndAsset(manifestData, asset, settings) {
        return __awaiter(this, void 0, void 0, function* () {
            const settingsStr = settings ? (typeof settings === 'string' ? settings : JSON.stringify(settings)) : undefined;
            const reader = yield getNeonBinary().readerFromManifestDataAndAsset(manifestData, asset, settingsStr);
            return new Reader(reader);
        });
    }
    // Non-neon methods, copied from c2pa-js
    activeLabel() {
        var _a;
        const manifestStore = this.json();
        return (_a = manifestStore.active_manifest) !== null && _a !== void 0 ? _a : undefined;
    }
    getActive() {
        var _a;
        const manifestStore = this.json();
        const activeManifest = manifestStore.active_manifest;
        if (!activeManifest) {
            return undefined;
        }
        return (_a = manifestStore.manifests) === null || _a === void 0 ? void 0 : _a[activeManifest];
    }
    getHandle() {
        return this.reader;
    }
}
