"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.KeyPairUpdateRequest = void 0;
/**
 * Represents a request to update aes exchange keys following the creation of a new key pair for a data owner.
 */
const MaintenanceTask_1 = require("../../icc-api/model/MaintenanceTask");
var KeyPairUpdateRequest;
(function (KeyPairUpdateRequest) {
    /**
     * Create a key pair update request from a maintenance task.
     */
    function fromMaintenanceTask(task) {
        if (task.taskType !== KeyPairUpdateRequest.TASK_TYPE)
            throw new Error(`Key pair update tasks should have task type ${KeyPairUpdateRequest.TASK_TYPE}, but got task with type ${task.taskType}`);
        function findStringProp(propId) {
            var _a, _b, _c;
            const prop = (_a = task.properties) === null || _a === void 0 ? void 0 : _a.find((x) => x.id === propId);
            if (!prop)
                throw new Error(`Task is missing required string property ${propId} for KeyPairUpdateRequest. ${JSON.stringify(task)}`);
            const propValue = (_b = prop.typedValue) === null || _b === void 0 ? void 0 : _b.stringValue;
            if (!propValue)
                throw new Error(`Invalid value ${(_c = prop.typedValue) === null || _c === void 0 ? void 0 : _c.stringValue} for property ${propId} for KeyPairUpdateRequest. ${JSON.stringify(task)}`);
            return propValue;
        }
        return {
            concernedDataOwnerId: findStringProp(KeyPairUpdateRequest.OWNER_ID_PROP_ID),
            newPublicKey: findStringProp(KeyPairUpdateRequest.OWNER_PUB_PROP_ID),
            originalTask: task,
        };
    }
    KeyPairUpdateRequest.fromMaintenanceTask = fromMaintenanceTask;
})(KeyPairUpdateRequest || (exports.KeyPairUpdateRequest = KeyPairUpdateRequest = {}));
(function (KeyPairUpdateRequest) {
    /**
     * @internal this field is intended for internal use only and may be changed in future without notice
     */
    KeyPairUpdateRequest.OWNER_ID_PROP_ID = 'dataOwnerConcernedId';
    /**
     * @internal this field is intended for internal use only and may be changed in future without notice
     */
    KeyPairUpdateRequest.OWNER_PUB_PROP_ID = 'dataOwnerConcernedPubKey';
    /**
     * @internal this field is intended for internal use only and may be changed in future without notice
     */
    KeyPairUpdateRequest.TASK_TYPE = MaintenanceTask_1.MaintenanceTask.TaskTypeEnum.KeyPairUpdate;
})(KeyPairUpdateRequest || (exports.KeyPairUpdateRequest = KeyPairUpdateRequest = {}));
//# sourceMappingURL=KeyPairUpdateRequest.js.map