import { z } from "zod";

import { type Datum } from "./datum.svelte.ts";
import { presentation_schema } from "./presentation.svelte.ts";

export const field_schema = z.object({
  id: z.string(),
  name: z.string(),
  table_label: z.string().nullish().transform((x) => x ?? undefined),
  presentation: presentation_schema,
  table_width_px: z.number(),
  ordinality: z.number(),
});

export type Field = z.infer<typeof field_schema>;

export const field_info_schema = z.object({
  field: field_schema,
  has_default: z.boolean(),
  not_null: z.boolean(),
});

export type FieldInfo = z.infer<typeof field_info_schema>;

// -------- Table Utils -------- //
// TODO move this to its own module

export type Row = {
  key: string | number;
  data: Datum[];
};
