// Re-export the shared types from @edr/types so existing local imports keep
// working. Canonical source: packages/types/src/freight/file_upload_settings.ts
//
// NOTE: @edr/types is compiled to CommonJS (see packages/types/tsconfig.json),
// so its dist/index.js uses `Object.defineProperty(exports, ...)` instead of
// real ESM exports. Vite can't pull runtime values out of it — only TypeScript
// type-only imports (which are erased at build time) work cleanly. That's why
// `getMinFiles` / `getEffectiveMaxFiles` are defined locally below instead of
// re-exported from the package. They mirror the canonical logic in
// packages/types/src/freight/file_upload_settings.ts exactly.
import type { Freight } from "@edr/types";

export type FileUploadEntity = Freight.FileUploadEntity;
export type FileUploadField = Freight.IFileUploadField;
export type FileUploadSetting = Freight.IFileUploadSetting;
export type CreateFileUploadFieldDto = Freight.CreateFileUploadFieldDto;
export type CreateFileUploadSettingDto = Freight.CreateFileUploadSettingDto;
export type UpdateFileUploadFieldDto = Freight.UpdateFileUploadFieldDto;
export type UpdateFileUploadSettingDto = Freight.UpdateFileUploadSettingDto;

/**
 *   required | multiple | min | max
 *   ---------|----------|-----|-----------------
 *   no       | no       |  0  | 1
 *   yes      | no       |  1  | 1
 *   no       | yes      |  0  | field.maxFiles
 *   yes      | yes      |  1  | field.maxFiles
 */
export function getMinFiles(
  field: Pick<FileUploadField, "isRequired">,
): number {
  return field.isRequired ? 1 : 0;
}

export function getEffectiveMaxFiles(
  field: Pick<FileUploadField, "isMultiple" | "maxFiles">,
): number {
  return field.isMultiple ? Math.max(1, field.maxFiles) : 1;
}
