"use strict";
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
const instantiation = require("../../../platform/instantiation/common/instantiation.js");
const uri = require("../../../base/common/uri.js");
const types = require("../../../base/common/types.js");
const IBulkEditService = instantiation.createDecorator("IWorkspaceEditService");
function isWorkspaceFileEdit(thing) {
  return types.isObject(thing) && (Boolean(thing.newUri) || Boolean(thing.oldUri));
}
function isWorkspaceTextEdit(thing) {
  return types.isObject(thing) && uri.URI.isUri(thing.resource) && types.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;
  }
}
exports.IBulkEditService = IBulkEditService;
exports.ResourceEdit = ResourceEdit;
exports.ResourceFileEdit = ResourceFileEdit;
exports.ResourceTextEdit = ResourceTextEdit;
