# Form: Initialize a new project in the ontoref ecosystem
# Drives reflection/modes/new_project.ncl with concrete parameter values.
#
# No roundtrip input (project doesn't exist yet).
# Usage:
#   typedialog form reflection/forms/new_project.ncl \
#     --ncl-template reflection/templates/create_project.nu.j2 \
#     --output scripts/create-{project_name}.nu
#
# Agent query:
#   nickel export reflection/forms/new_project.ncl \
#     | get elements \
#     | where type != "section_header" \
#     | where type != "section" \
#     | select name prompt required default

{
  name        = "New Project",
  description = "Initialize a new project in the ecosystem. Produces a Nushell script ready to execute.",

  elements = [

    # ── Identity ─────────────────────────────────────────────────────────────
    { type = "section_header", name = "identity_header",
      title = "Project Identity", border_top = true, border_bottom = true },

    { type = "text", name = "project_name",
      prompt      = "Project name (identifier)",
      required    = true,
      placeholder = "my-service",
      help        = "Lowercase, kebab-case. Used as NATS subject prefix (ecosystem.{name}.*), kogral id, syntaxis project name." },

    { type = "text", name = "project_description",
      prompt      = "One-line description",
      required    = true,
      placeholder = "Handles user authentication for the ecosystem" },

    { type = "select", name = "project_type",
      prompt  = "Project type",
      required = true,
      options = [
        { value = "rust-service",  label = "Rust binary service (has NATS + SurrealDB)" },
        { value = "rust-library",  label = "Rust library crate (compile-time dependency only)" },
        { value = "nu-scripts",    label = "Nushell scripts (operational automation)" },
        { value = "mixed",         label = "Mixed (Rust + Nushell + Nickel)" },
      ] },

    # ── Paths ────────────────────────────────────────────────────────────────
    { type = "section_header", name = "paths_header",
      title = "Paths", border_top = true, border_bottom = true },

    { type = "text", name = "project_dir",
      prompt   = "Absolute path for the new project",
      required = true,
      placeholder = "/Users/Akasha/Development/my-service",
      help     = "Parent directory must exist. The directory itself must not exist yet." },

    { type = "text", name = "ontoref_dir",
      prompt   = "Absolute path to ontoref checkout",
      required = true,
      default  = "/Users/Akasha/Development/ontoref",
      help     = "Used to copy .ontology/ templates and reflection/schema.ncl." },

    # ── Git ──────────────────────────────────────────────────────────────────
    { type = "section_header", name = "git_header",
      title = "Git", border_top = true, border_bottom = true },

    { type = "text", name = "git_remote_url",
      prompt      = "Remote git URL (optional, added after init)",
      required    = false,
      placeholder = "https://repo.jesusperez.pro/jesus/my-service",
      help        = "Leave blank to skip remote setup." },

    { type = "text", name = "default_branch",
      prompt   = "Default branch name",
      default  = "main",
      required = true },

    # ── Ecosystem tools ──────────────────────────────────────────────────────
    { type = "section_header", name = "tools_header",
      title = "Ecosystem Tools", border_top = true, border_bottom = true },

    { type = "section", name = "tools_note",
      content = "All tools are optional. The project functions without them.\nADR-003: only NATS and SurrealDB are shared external runtime dependencies." },

    { type = "confirm", name = "use_nats",
      prompt  = "Configure NATS stream (ecosystem.{project_name}.*)?",
      default = true,
      help    = "Creates the NATS stream for the project's ecosystem subjects. Idempotent." },

    { type = "text", name = "nats_url",
      prompt   = "NATS server URL",
      default  = "nats://localhost:4222",
      when     = "use_nats == true" },

    { type = "confirm", name = "use_surrealdb",
      prompt  = "Note SurrealDB namespace for this project?",
      default = false,
      help    = "Does not create the namespace — just records it in the generated script." },

    { type = "text", name = "surrealdb_namespace",
      prompt   = "SurrealDB namespace",
      when     = "use_surrealdb == true",
      placeholder = "my-service" },

    { type = "confirm", name = "use_kogral",
      prompt  = "Initialize kogral graph (.kogral/)?",
      default = false,
      help    = "kogral init is optional. Execution continues if kogral is not installed." },

    { type = "confirm", name = "use_syntaxis",
      prompt  = "Register in syntaxis?",
      default = false,
      help    = "syntaxis project create is optional. Execution continues if syntaxis is not installed." },

    # ── Ontology ─────────────────────────────────────────────────────────────
    { type = "section_header", name = "ontology_header",
      title = "Project Ontology", border_top = true, border_bottom = true },

    { type = "section", name = "ontology_note",
      content = "The .ontology/ templates are copied from ontoref. The project owner fills in:\n  core.ncl  — invariants, tensions, practices specific to this project\n  state.ncl — current and desired states per dimension\n  gate.ncl  — active membranes protecting key conditions" },

    { type = "confirm", name = "copy_ontology_template",
      prompt  = "Copy .ontology/ templates from ontoref?",
      default = true,
      help    = "Copies core.ncl, state.ncl, gate.ncl stubs. Project owner fills in project-specific content." },

    # ── Review ───────────────────────────────────────────────────────────────
    { type = "section_header", name = "review_header",
      title = "Review", border_top = true },

    { type = "section", name = "review_note",
      content = "The generated script will:\n  1. git init {project_dir}\n  2. Copy .ontology/ templates (if selected)\n  3. Configure NATS stream (if selected)\n  4. Register in kogral / syntaxis (if selected, optional)\n  5. Publish ecosystem.project.created to NATS (best-effort)" },

    { type = "confirm", name = "ready_to_generate",
      prompt  = "Generate the create-project script?",
      default = true },
  ],
}
