"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());
    });
};
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.PagesClient = void 0;
const ta_json_1 = require("ta-json");
const guard_1 = __importDefault(require("../guard"));
const page_resource_1 = require("../models/pages/page-resource");
const response_handler_1 = require("./response-handler");
class PagesClient {
    constructor(client) {
        this._client = client;
    }
    getPageByNameAsync(name, culture, entityId, cancelCallback) {
        return __awaiter(this, void 0, void 0, function* () {
            guard_1.default.stringNotNullOrEmpty(name);
            guard_1.default.notNullOrUndefined(culture);
            return this.getPageByIdentifierAsync(name, culture, entityId, cancelCallback);
        });
    }
    getPageByIdentifierAsync(identifier, culture, entityId, cancelCallback) {
        return __awaiter(this, void 0, void 0, function* () {
            guard_1.default.stringNotNullOrEmpty(identifier);
            guard_1.default.notNullOrUndefined(culture);
            const link = yield this._client.linkHelper.pageResourceToLinkAsync(identifier, culture, entityId);
            const response = yield this._client.raw.getAsync(link.href, undefined, cancelCallback);
            response_handler_1.ResponseHandler.handleErrors(response);
            return ta_json_1.TaJson.deserialize(response.content, page_resource_1.PageResource);
        });
    }
    getPageByIdAsync(id, culture, entityId, cancelCallback) {
        return __awaiter(this, void 0, void 0, function* () {
            guard_1.default.validId(id);
            guard_1.default.notNullOrUndefined(culture);
            const link = yield this._client.linkHelper.pageResourceToLinkAsync(id, culture, entityId);
            const response = yield this._client.raw.getAsync(link.href, undefined, cancelCallback);
            response_handler_1.ResponseHandler.handleErrors(response);
            return ta_json_1.TaJson.deserialize(response.content, page_resource_1.PageResource);
        });
    }
}
exports.PagesClient = PagesClient;
//# sourceMappingURL=pages-client.js.map