import type { FieldError, StoredSubmission } from '@platform-modules/forms'

export type { FieldError, StoredSubmission }

export type SubmitResult = { ok: true; id: string } | { ok: false; errors: FieldError[] }

/** PUBLIC submit — the host's intake route. The SERVER runs validate + anti-spam; the browser only POSTs. */
export type SubmitFn = (formId: string, data: Record<string, unknown>, renderToken?: string) => Promise<SubmitResult>

/** ADMIN inbox — admin-authorized, formId-scoped routes. NO cross-form global read (IDOR floor). */
export interface SubmissionClient {
  list(formId: string, opts?: { limit?: number; cursor?: string; includeSpam?: boolean }): Promise<{
    items: StoredSubmission[]
    nextCursor?: string
  }>
  get(formId: string, id: string): Promise<StoredSubmission | null>
  delete(formId: string, id: string): Promise<void>
}
