/*
 * Copyright 2025 Palantir Technologies, Inc. All rights reserved.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

export function extractRdpFieldNames(rdpConfig) {
  if (!rdpConfig) {
    return new Set();
  }
  return new Set(Object.keys(rdpConfig));
}
function deleteField(obj, field) {
  delete obj[field];
}
function setField(obj, field, value) {
  obj[field] = value;
}
function stripRdpFields(value, rdpFields) {
  if (rdpFields.size === 0) {
    return value;
  }
  const result = {
    ...value
  };
  for (const field of rdpFields) {
    deleteField(result, field);
  }
  return result;
}
function isSuperset(superset, subset) {
  for (const field of subset) {
    if (!superset.has(field)) {
      return false;
    }
  }
  return true;
}
function filterToFields(value, allowedFields) {
  const result = {
    ...value
  };
  const allFields = Object.keys(result);
  for (const field of allFields) {
    if (!allowedFields.has(field)) {
      deleteField(result, field);
    }
  }
  return result;
}
export function mergeObjectFields(sourceValue, sourceRdpFields, targetRdpFields, targetCurrentValue) {
  if (targetRdpFields.size === 0) {
    return stripRdpFields(sourceValue, sourceRdpFields);
  }
  if (isSuperset(sourceRdpFields, targetRdpFields)) {
    if (sourceRdpFields.size === targetRdpFields.size) {
      return sourceValue;
    }
    return filterToFields(sourceValue, targetRdpFields);
  }
  const merged = {
    ...sourceValue
  };
  if (targetCurrentValue) {
    for (const field of targetRdpFields) {
      if (!sourceRdpFields.has(field) && field in targetCurrentValue) {
        setField(merged, field, targetCurrentValue[field]);
      }
    }
  }
  return merged;
}
//# sourceMappingURL=rdpFieldOperations.js.map