import type { RouteRef } from "./route"

/**
 * CRUD configuration shared by IndexPage / ShowPage / FormPanel.
 * Each operation is independently optional so a page can be read-only,
 * create-only, etc.
 */

export interface CreateConfig<TItem = Record<string, unknown>> {
  create: RouteRef
  /**
   * Transform the form payload before submission. Return value is what
   * actually gets POST'd.
   */
  transform?: (data: TItem) => TItem | Record<string, unknown>
  /** Fields to reload from the server after a successful create. */
  fieldsForceReload?: string[]
  /** Custom button text. */
  buttonText?: string
  /** Hide the create button from the UI while keeping the action wired. */
  hideButton?: boolean
}

export interface UpdateConfig<TItem = Record<string, unknown>> {
  update: RouteRef & {
    /** Property on the row that identifies the record (default `"id"`). */
    key?: string
  }
  /** Auto-save on field change instead of requiring an explicit save click. */
  autoSave?: boolean
  /** Show or hide the explicit save button. */
  showSaveButton?: boolean
  /** Run client-side validation before submitting. */
  validation?: boolean
  transform?: (data: TItem) => TItem | Record<string, unknown>
  fieldsForceReload?: string[]
}

export interface DeleteConfig {
  delete: RouteRef & {
    key?: string
  }
  /** If true, prompt the user to type a confirmation string. */
  requiresInputConfirmation?: boolean
  /** Text the user must type to confirm. Default: row's display name. */
  confirmationText?: string
}
