// SPDX-License-Identifier: Apache-2.0
import Mapper from "../validation/Mapper";
const OPTIONAL_KEYS = Symbol("optionalKeys");
export 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);
    }
}
export function getOptionalFields(origin) {
    const properties = Reflect.getMetadata(OPTIONAL_KEYS, origin) ?? [];
    const result = {};
    properties.forEach((key) => (result[Mapper.renamePrivateProps(key)] = origin[key]));
    return result;
}
