import { SequenceForm } from "./SequenceForm";
import { EnumForm } from "./EnumForm";
import { ExtensionForm } from "./ExtensionForm";
import { ViewForm } from "./ViewForm";
import { IndexForm } from "./IndexForm";
import { ConstraintForm } from "./ConstraintForm";
import { FunctionForm } from "./FunctionForm";
import { TriggerForm } from "./TriggerForm";
import { RoleForm } from "./RoleForm";
import type { ObjectKind, DdlParams } from "../../../lib/objectCrud";

interface Props {
  connectionId: string;
  kind: ObjectKind;
  params: DdlParams;
  schemas?: string[];
  onChange: (p: DdlParams) => void;
}

/** Renders the matching CRUD form for a kind (shared by the context menu and the form tab). */
export function KindForm({ connectionId, kind, params, schemas, onChange }: Props) {
  switch (kind) {
    case "sequence":
      return <SequenceForm params={params} schemas={schemas} onChange={onChange} />;
    case "enum":
      return <EnumForm params={params} schemas={schemas} onChange={onChange} />;
    case "extension":
      return (
        <ExtensionForm
          connectionId={connectionId}
          params={params}
          schemas={schemas}
          onChange={onChange}
        />
      );
    case "view":
      return <ViewForm params={params} schemas={schemas} onChange={onChange} />;
    case "index":
      return (
        <IndexForm
          connectionId={connectionId}
          params={params}
          schemas={schemas}
          onChange={onChange}
        />
      );
    case "constraint":
      return (
        <ConstraintForm
          connectionId={connectionId}
          params={params}
          schemas={schemas}
          onChange={onChange}
        />
      );
    case "function":
    case "procedure":
      return <FunctionForm kind={kind} params={params} schemas={schemas} onChange={onChange} />;
    case "trigger":
      return (
        <TriggerForm
          connectionId={connectionId}
          params={params}
          schemas={schemas}
          onChange={onChange}
        />
      );
    case "table":
      // Unreachable in the form-tab flow (ObjectFormTab delegates table to
      // TableForm directly); kept only so the switch is exhaustive.
      return null;
    case "role":
      return <RoleForm connectionId={connectionId} params={params} onChange={onChange} />;
  }
}