"use strict";
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
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);

// src/models/fields/utils.ts
var utils_exports = {};
__export(utils_exports, {
  defaultCompareCallback: () => defaultCompareCallback,
  defaultGetArgumentsCallback: () => defaultGetArgumentsCallback,
  defaultNewInstanceArgumentsCallback: () => defaultNewInstanceArgumentsCallback,
  defaultOptionsCallback: () => defaultOptionsCallback,
  defaultToStringCallback: () => defaultToStringCallback,
  getRelatedToAsString: () => getRelatedToAsString
});
module.exports = __toCommonJS(utils_exports);
async function defaultToStringCallback(engine, field, _, customParams = void 0) {
  let customImports = [];
  let stringifiedCustomAttributes = "{}";
  if (engine.fields.fieldToString) {
    const stringifiedField = engine.fields.fieldToString(field["__customAttributes"]);
    customImports = stringifiedField.imports;
    stringifiedCustomAttributes = stringifiedField.result;
  }
  const stringfieldDefaultValue = field["__defaultValue"] === void 0 ? void 0 : JSON.stringify(field["__defaultValue"]);
  return {
    stringfied: `models.fields.${field["__typeName"]}.new(${customParams?.constructorParams ? `${customParams.constructorParams}` : ""})${typeof field["__primaryKey"] === "boolean" ? `.primaryKey(${field["__primaryKey"]})` : ""}${stringfieldDefaultValue !== void 0 ? `.default(${typeof field["__defaultValue"] === "string" ? `"${stringfieldDefaultValue}"` : stringfieldDefaultValue})` : ""}${typeof field["__allowNull"] === "boolean" ? `.allowNull(${field["__allowNull"]})` : ""}${typeof field["__unique"] === "boolean" ? `.unique(${field["__unique"]})` : ""}${typeof field["__dbIndex"] === "boolean" ? `.dbIndex(${field["__dbIndex"]})` : ""}${typeof field["__databaseName"] === "string" ? `.databaseName("${field["__databaseName"]}")` : ""}${typeof field["__underscored"] === "boolean" ? `.underscored(${field["__underscored"]})` : ""}${typeof stringifiedCustomAttributes === "string" ? `.setCustomAttributes(${stringifiedCustomAttributes})` : ""}${customParams?.builderParams ? `${customParams.builderParams}` : ""}`,
    customImports
  };
}
__name(defaultToStringCallback, "defaultToStringCallback");
function defaultCompareCallback(engine, existingField, newField, _) {
  let isCustomAttributesEqual = true;
  if (engine.fields.compare) {
    const areCustomAttributesEqual = engine.fields.compare(existingField["__customAttributes"], newField["__customAttributes"]);
    isCustomAttributesEqual = areCustomAttributesEqual;
  }
  const isTypeNameEqual = existingField["__typeName"] === newField["__typeName"];
  const isAllowNullEqual = existingField["__allowNull"] === newField["__allowNull"];
  const isPrimaryKeyEqual = existingField["__primaryKey"] === newField["__primaryKey"];
  const isDefaultValueEqual = existingField["__defaultValue"] === newField["__defaultValue"];
  const isUniqueEqual = existingField["__unique"] === newField["__unique"];
  const isDbIndexEqual = existingField["__dbIndex"] === newField["__dbIndex"];
  const isDatabaseNameEqual = existingField["__databaseName"] === newField["__databaseName"];
  const isUnderscoredEqual = existingField["__underscored"] === newField["__underscored"];
  const changedAttributes = [
    !isTypeNameEqual && "typeName",
    !isAllowNullEqual && "allowNull",
    !isCustomAttributesEqual && "customAttributes",
    !isPrimaryKeyEqual && "primaryKey",
    !isDefaultValueEqual && "defaultValue",
    !isUniqueEqual && "unique",
    !isDbIndexEqual && "dbIndex",
    !isDatabaseNameEqual && "databaseName",
    !isUnderscoredEqual && "underscored"
  ].filter((attr) => typeof attr === "string");
  return [
    changedAttributes.length === 0,
    changedAttributes
  ];
}
__name(defaultCompareCallback, "defaultCompareCallback");
function defaultOptionsCallback(setFieldValue, oldField, _) {
  setFieldValue("__allowNull", "allowNull", oldField["__allowNull"]);
  setFieldValue("__customAttributes", "customAttributes", oldField["__customAttributes"]);
  setFieldValue("__defaultValue", "defaultValue", oldField["__defaultValue"]);
  setFieldValue("__dbIndex", "dbIndex", oldField["__dbIndex"]);
  setFieldValue("__databaseName", "databaseName", oldField["__databaseName"]);
  setFieldValue("__primaryKey", "primaryKey", oldField["__primaryKey"]);
  setFieldValue("__underscored", "underscored", oldField["__underscored"]);
  setFieldValue("__unique", "unique", oldField["__unique"]);
  setFieldValue("__isAuto", "isAuto", oldField["__isAuto"]);
  setFieldValue("__fieldName", "fieldName", oldField["__fieldName"]);
  setFieldValue("__model", void 0, oldField["__model"]);
}
__name(defaultOptionsCallback, "defaultOptionsCallback");
function defaultNewInstanceArgumentsCallback(_field, _defaultNewInstanceArgumentsCallback) {
  return [];
}
__name(defaultNewInstanceArgumentsCallback, "defaultNewInstanceArgumentsCallback");
function getRelatedToAsString(field) {
  const relatedTo = field["__relatedTo"];
  const relatedToAsString = field["__relatedToAsString"];
  if (typeof relatedToAsString !== "string") {
    if (typeof relatedTo === "function" && relatedTo["$$type"] !== "$PModel") field["__relatedToAsString"] = relatedTo()["__getName"]();
    else if (typeof relatedTo === "string") field["__relatedToAsString"] = relatedTo;
    else field["__relatedToAsString"] = relatedTo["__getName"]();
  }
}
__name(getRelatedToAsString, "getRelatedToAsString");
function defaultGetArgumentsCallback(field, _) {
  return {
    $field: field,
    $model: field["__model"],
    typeName: field["__typeName"],
    fieldName: field["__fieldName"],
    modelName: field["__model"]?.["__getName"]?.() || "",
    isAuto: field["__isAuto"],
    primaryKey: field["__primaryKey"],
    defaultValue: field["__defaultValue"],
    allowNull: field["__allowNull"],
    unique: field["__unique"],
    dbIndex: field["__dbIndex"],
    databaseName: field["__databaseName"],
    underscored: field["__underscored"],
    customAttributes: field["__customAttributes"]
  };
}
__name(defaultGetArgumentsCallback, "defaultGetArgumentsCallback");
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
  defaultCompareCallback,
  defaultGetArgumentsCallback,
  defaultNewInstanceArgumentsCallback,
  defaultOptionsCallback,
  defaultToStringCallback,
  getRelatedToAsString
});
