import { createDecorator } from "../../../platform/instantiation/common/instantiation.mjs";
import { URI } from "../../../base/common/uri.mjs";
import { isObject } from "../../../base/common/types.mjs";
const IBulkEditService = createDecorator("IWorkspaceEditService");
function isWorkspaceFileEdit(thing) {
  return isObject(thing) && (Boolean(thing.newUri) || Boolean(thing.oldUri));
}
function isWorkspaceTextEdit(thing) {
  return isObject(thing) && URI.isUri(thing.resource) && isObject(thing.edit);
}
class ResourceEdit {
  constructor(metadata) {
    this.metadata = metadata;
  }
  static convert(edit) {
    return edit.edits.map((edit2) => {
      if (isWorkspaceTextEdit(edit2)) {
        return new ResourceTextEdit(edit2.resource, edit2.edit, edit2.modelVersionId, edit2.metadata);
      }
      if (isWorkspaceFileEdit(edit2)) {
        return new ResourceFileEdit(edit2.oldUri, edit2.newUri, edit2.options, edit2.metadata);
      }
      throw new Error("Unsupported edit");
    });
  }
}
class ResourceTextEdit extends ResourceEdit {
  constructor(resource, textEdit, versionId, metadata) {
    super(metadata);
    this.resource = resource;
    this.textEdit = textEdit;
    this.versionId = versionId;
  }
}
class ResourceFileEdit extends ResourceEdit {
  constructor(oldResource, newResource, options, metadata) {
    super(metadata);
    this.oldResource = oldResource;
    this.newResource = newResource;
    this.options = options;
  }
}
export {
  IBulkEditService,
  ResourceEdit,
  ResourceFileEdit,
  ResourceTextEdit
};
