"use strict";
// SPDX-License-Identifier: Apache-2.0
var __importDefault = (this && this.__importDefault) || function (mod) {
    return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.OptionalField = OptionalField;
exports.getOptionalFields = getOptionalFields;
const Mapper_1 = __importDefault(require("../validation/Mapper"));
const OPTIONAL_KEYS = Symbol("optionalKeys");
function OptionalField() {
    return registerProperty;
}
function registerProperty(target, propertyKey) {
    let properties = Reflect.getMetadata(OPTIONAL_KEYS, target);
    if (properties) {
        properties.push(propertyKey);
    }
    else {
        properties = [propertyKey];
        Reflect.defineMetadata(OPTIONAL_KEYS, properties, target);
    }
}
function getOptionalFields(origin) {
    const properties = Reflect.getMetadata(OPTIONAL_KEYS, origin) ?? [];
    const result = {};
    properties.forEach((key) => (result[Mapper_1.default.renamePrivateProps(key)] = origin[key]));
    return result;
}
