"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
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 __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var printDatasources_exports = {};
__export(printDatasources_exports, {
  printDatamodelObject: () => printDatamodelObject,
  printDatasources: () => printDatasources
});
module.exports = __toCommonJS(printDatasources_exports);
var import_chunk_2R6DII47 = require("../chunk-2R6DII47.js");
var import_chunk_2ESYSVXG = require("../chunk-2ESYSVXG.js");
var import_indent_string = (0, import_chunk_2ESYSVXG.__toESM)((0, import_chunk_2R6DII47.require_indent_string)());
function printDatasources(internalDatasources) {
  return internalDatasources.map((d) => String(new InternalDataSourceClass(d))).join("\n\n");
}
var tab = 2;
var InternalDataSourceClass = class {
  constructor(dataSource) {
    this.dataSource = dataSource;
  }
  toString() {
    const { dataSource } = this;
    const obj = {
      provider: dataSource.provider,
      url: dataSource.url
    };
    if (dataSource.config && typeof dataSource.config === "object") {
      Object.assign(obj, dataSource.config);
    }
    return `datasource ${dataSource.name} {
${(0, import_indent_string.default)(printDatamodelObject(obj), tab)}
}`;
  }
};
function printDatamodelObject(obj) {
  const maxLength = Object.keys(obj).reduce((max, curr) => Math.max(max, curr.length), 0);
  return Object.entries(obj).map(
    ([key, value]) => `${key.padEnd(maxLength)} = ${typeof value === "object" && value && value.value ? JSON.stringify(value.value) : JSON.stringify(value)}`
  ).join("\n");
}
