# homelab-docs.nix - Main documentation generator package
{
  lib,
  stdenv,
  writeShellScriptBin,
  jq,
  nixfmt,
}: let
  # Import individual CLI generators
  docsGenerator = import ./main.nix {inherit writeShellScriptBin;};
  fleetDocsGenerator = import ./fleet.nix {inherit writeShellScriptBin jq;};
  nodeDocsGenerator = import ./nodes.nix {inherit writeShellScriptBin jq;};
  serviceDocsGenerator = import ./services.nix {inherit writeShellScriptBin jq;};
  deploymentDocsGenerator = import ./deployment.nix {inherit writeShellScriptBin jq;};
  readmeGenerator = import ./readme.nix {inherit writeShellScriptBin jq;};
in
  stdenv.mkDerivation {
    pname = "homelab-docs";
    version = "1.0.0";

    dontUnpack = true;
    dontBuild = true;

    installPhase = ''
      mkdir -p $out/bin

      # Install all the generators
      cp ${docsGenerator}/bin/homelab-generate-docs $out/bin/
      cp ${fleetDocsGenerator}/bin/homelab-docs-fleet $out/bin/
      cp ${nodeDocsGenerator}/bin/homelab-docs-nodes $out/bin/
      cp ${serviceDocsGenerator}/bin/homelab-docs-services $out/bin/
      cp ${deploymentDocsGenerator}/bin/homelab-docs-deployment $out/bin/
      cp ${readmeGenerator}/bin/homelab-docs-readme $out/bin/

      # Make sure they're executable
      chmod +x $out/bin/*
    '';

    meta = with lib; {
      description = "Documentation generator for homelab colmena deployments";
      longDescription = ''
        A collection of tools to generate comprehensive documentation
        for homelab deployments managed with colmena. Extracts configuration
        from flakes and generates markdown documentation.
      '';
      license = licenses.mit;
      maintainers = [];
      platforms = platforms.all;
    };
  }
