"use strict";
var __create = Object.create;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __getProtoOf = Object.getPrototypeOf;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
  for (var name in all)
    __defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
  if (from && typeof from === "object" || typeof from === "function") {
    for (let key of __getOwnPropNames(from))
      if (!__hasOwnProp.call(to, key) && key !== except)
        __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
  }
  return to;
};
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
  // If the importer is in node compatibility mode or this is not an ESM
  // file that has been converted to a CommonJS file using a Babel-
  // compatible transform (i.e. "__esModule" has not been set), then set
  // "default" to the CommonJS "module.exports" for node compatibility.
  isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
  mod
));
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var chunk_GG6F5QWR_exports = {};
__export(chunk_GG6F5QWR_exports, {
  DbDrop: () => DbDrop
});
module.exports = __toCommonJS(chunk_GG6F5QWR_exports);
var import_chunk_PLHXV7LD = require("./chunk-PLHXV7LD.js");
var import_chunk_KCMQOXUX = require("./chunk-KCMQOXUX.js");
var import_chunk_FFLD75KX = require("./chunk-FFLD75KX.js");
var import_chunk_PZ4BRULM = require("./chunk-PZ4BRULM.js");
var import_chunk_2CL32XWS = require("./chunk-2CL32XWS.js");
var import_chunk_F7KSWWYN = require("./chunk-F7KSWWYN.js");
var import_internals = require("@prisma/internals");
var import_prompts = __toESM(require("prompts"));
(0, import_chunk_F7KSWWYN.init_colors)();
(0, import_chunk_PZ4BRULM.init_ensureDatabaseExists)();
(0, import_chunk_2CL32XWS.init_errors)();
(0, import_chunk_KCMQOXUX.init_getSchemaPathAndPrint)();
(0, import_chunk_FFLD75KX.init_printDatasource)();
var _DbDrop = class _DbDrop2 {
  static new() {
    return new _DbDrop2();
  }
  async parse(argv) {
    const args = (0, import_internals.arg)(argv, {
      "--help": Boolean,
      "-h": "--help",
      "--preview-feature": Boolean,
      "--force": Boolean,
      "-f": "--force",
      "--schema": String,
      "--telemetry-information": String
    });
    if ((0, import_internals.isError)(args)) {
      return this.help(args.message);
    }
    await (0, import_internals.checkUnsupportedDataProxy)("db drop", args, true);
    if (args["--help"]) {
      return this.help();
    }
    if (!args["--preview-feature"]) {
      throw new import_chunk_PLHXV7LD.PreviewFlagError();
    }
    (0, import_internals.loadEnvFile)({ schemaPath: args["--schema"], printMessage: true });
    const schemaPath = await (0, import_chunk_KCMQOXUX.getSchemaPathAndPrint)(args["--schema"]);
    const datasourceInfo = await (0, import_chunk_PZ4BRULM.getDatasourceInfo)({ schemaPath, throwIfEnvError: true });
    (0, import_chunk_FFLD75KX.printDatasource)({ datasourceInfo });
    const schemaDir = await (0, import_internals.getSchemaDir)(schemaPath);
    console.info();
    if (!args["--force"]) {
      if (!(0, import_internals.canPrompt)()) {
        throw new import_chunk_2CL32XWS.DbDropNeedsForceError("drop");
      }
      const confirmation = await (0, import_prompts.default)({
        type: "text",
        name: "value",
        message: `Enter the ${datasourceInfo.prettyProvider} database name "${datasourceInfo.dbName}" to drop it.
Location: "${datasourceInfo.dbLocation}".
${(0, import_chunk_F7KSWWYN.red)("All data will be lost")}.`
      });
      console.info();
      if (!confirmation.value) {
        console.info("Drop cancelled.");
        process.exit(130);
      } else if (confirmation.value !== datasourceInfo.dbName) {
        throw Error(`The database name entered "${confirmation.value}" doesn't match "${datasourceInfo.dbName}".`);
      }
    }
    if (await (0, import_internals.dropDatabase)(datasourceInfo.url, schemaDir)) {
      return `${process.platform === "win32" ? "" : "\u{1F680}  "}The ${datasourceInfo.prettyProvider} database "${datasourceInfo.dbName}" from "${datasourceInfo.dbLocation}" was successfully dropped.
`;
    } else {
      return "";
    }
  }
  help(error) {
    if (error) {
      return new import_internals.HelpError(`
${(0, import_chunk_F7KSWWYN.bold)((0, import_chunk_F7KSWWYN.red)(`!`))} ${error}
${_DbDrop2.help}`);
    }
    return _DbDrop2.help;
  }
};
_DbDrop.help = (0, import_internals.format)(`
${process.platform === "win32" ? "" : "\u{1F4A3}  "}Drop the database

${(0, import_chunk_F7KSWWYN.bold)((0, import_chunk_F7KSWWYN.yellow)("WARNING"))} ${(0, import_chunk_F7KSWWYN.bold)(
  `Prisma db drop is currently in Preview (${(0, import_internals.link)("https://pris.ly/d/preview")}).
There may be bugs and it's not recommended to use it in production environments.`
)}
${(0, import_chunk_F7KSWWYN.dim)("When using any of the subcommands below you need to explicitly opt-in via the --preview-feature flag.")}

${(0, import_chunk_F7KSWWYN.bold)("Usage")}

  ${(0, import_chunk_F7KSWWYN.dim)("$")} prisma db drop [options] --preview-feature

${(0, import_chunk_F7KSWWYN.bold)("Options")}

   -h, --help   Display this help message
     --schema   Custom path to your Prisma schema
  -f, --force   Skip the confirmation prompt

${(0, import_chunk_F7KSWWYN.bold)("Examples")}

  Drop the database
  ${(0, import_chunk_F7KSWWYN.dim)("$")} prisma db drop --preview-feature

  Specify a schema
  ${(0, import_chunk_F7KSWWYN.dim)("$")} prisma db drop --preview-feature --schema=./schema.prisma

  Use --force to skip the confirmation prompt
  ${(0, import_chunk_F7KSWWYN.dim)("$")} prisma db drop --preview-feature --force
`);
var DbDrop = _DbDrop;
