import { RelationshipType, type CampaignId, type Document } from "@/lib/types";
import { LocationForm } from "./location/LocationForm";
import { MonsterForm } from "./monsters/MonsterForm";
import { NpcForm } from "./npc/NpcForm";
import { SceneForm } from "./scene/SceneForm";
import { SecretForm } from "./secret/SecretForm";
import { TreasureForm } from "./treasure/TreasureForm";

function assertUnreachable(_x: never): never {
  throw new Error("DocumentForm switch is not exhaustive");
}

/**
 * Renders a form for any document type depending on the relationship.
 */
export const DocumentForm = ({
  campaignId,
  relationshipType,
  onCreate,
}: {
  campaignId: CampaignId;
  relationshipType: RelationshipType;
  onCreate: (document: Document) => Promise<void>;
}) => {
  switch (relationshipType) {
    case RelationshipType.Locations:
      return <LocationForm campaign={campaignId} onCreate={onCreate} />;
    case RelationshipType.Monsters:
      return <MonsterForm campaign={campaignId} onCreate={onCreate} />;
    case RelationshipType.Npcs:
      return <NpcForm campaign={campaignId} onCreate={onCreate} />;
    case RelationshipType.Secrets:
      return <SecretForm campaign={campaignId} onCreate={onCreate} />;
    case RelationshipType.DiscoveredIn:
      return "Form not supported here";
    case RelationshipType.Treasures:
      return <TreasureForm campaign={campaignId} onCreate={onCreate} />;
    case RelationshipType.Scenes:
      return <SceneForm campaign={campaignId} onCreate={onCreate} />;
  }

  return assertUnreachable(relationshipType);
};
