{ config, lib, pkgs, inputs, ... }:

let
  artPkgs = lib.attrVals [
    #"armorpaint"
    "blender"
    "gimp"
    "inkscape"
    "krita"
    #"prusa-slicer"
  ] pkgs;
  handheldPkgs = lib.attrVals [
    "chatty"
    "gnome-text-editor"
    "megapixels"
  ] pkgs;
  pcPkgs = lib.attrVals [
    "brightnessctl"
    "clipman"
    "cyrus-sasl-xoauth2"
    "dracula-theme"
    "easyeffects"
    "gamescope"
    "libnotify"
    "mutt-wizard"
    "powertop"
    "prettypst"
    "wl-clipboard"
    # temporary home manager things
    "eww"
    "ifuse"
    "img2pdf"
    "inotify-tools"
    "jq"
    "libimobiledevice"
    "socat"
    "typst"
  ] pkgs ++ [ pkgs.wineWowPackages.stableFull ];
  serverPkgs = lib.attrVals [
    #"package"
  ] pkgs;

  spaceman-nvim = pkgs.vimUtils.buildVimPlugin {
    name = "spaceman-nvim";
    src = pkgs.fetchFromGitHub {
      owner = "FireIsGood";
      repo = "spaceman.nvim";
      rev = "7910d202073bcc5f567481426f771b3737451dd9";
      hash = "sha256-VvKce2uiFzv0TjoJfEX461p9tY9aE237Xr1q/Lw3Utw=";
    };
  };

in
{
  options = {
    stitchyconf = {
      form = lib.mkOption {
        default = "pc";
        description = "Add moar packages I don't need";
        type = lib.types.enum [ "pc" "handheld" "server" ];
      };
      artPkgs.enable = lib.mkEnableOption "Standard Linux Creative Suite";
    };
  };

  config = {
    environment.systemPackages = (lib.attrVals [
      "black"
      "btop"
      "clang-tools"
      "eza"
      "fd"
      "fzf"
      "git"
      "glib"
      "glsl_analyzer"
      "gnumake"
      "gnupg"
      "hugo"
      "lazygit"
      "mypy"
      "neofetch"
      "nixd"
      "p7zip"
      "pinentry"
      "ripgrep"
      "rust-analyzer"
      "rustfmt"
      "rustup"
      "tinymist"
      "unzip"
      "vhdl-ls"
      "vtsls"
      "wget"
      "zip"
      "zoxide"
    ] pkgs)
    ++ (lib.optionals config.stitchyconf.artPkgs.enable artPkgs)
    ++ (lib.optionals (config.stitchyconf.form == "pc") pcPkgs)
    ++ (lib.optionals (config.stitchyconf.form == "handheld") handheldPkgs)
    ++ (lib.optionals (config.stitchyconf.form == "server") serverPkgs)
    ++ [ pkgs.nodePackages.prettier ];

    # To-do figure out how to section these off
    programs = {
      neovim = {
        enable = true;
        viAlias = true;
        vimAlias = true;
        defaultEditor = true;
        configure = {
          customRC = builtins.readFile ../config/nvim/init.vim;
          packages.myVimPackage = with pkgs.vimPlugins; {
            start = [
              conform-nvim
              bufferline-nvim
              cmp-nvim-lsp
              cmp_luasnip
              gitsigns-nvim
              indent-blankline-nvim
              lazy-nvim
              luasnip
              mini-nvim
              neo-tree-nvim
              nvim-cmp
              nvim-lspconfig
              (nvim-treesitter.withPlugins (
                plugins: with plugins; [
                  glsl
                  javascript
                  markdown
                ]
              ))
              nvim-web-devicons
              render-markdown-nvim
              spaceman-nvim
              telescope-nvim
              telescope-undo-nvim
              toggleterm-nvim
              tokyonight-nvim
              typst-vim
              vim-lsp-cxx-highlight
              which-key-nvim
            ];
          };
        };
      };
      nix-ld.enable = true;
      virt-manager.enable = true;
      zsh.enable = true;
    };

    nixpkgs.overlays = [
      (final: prev: {
        # Because Luck Smith hasn't released in 2 years
        mutt-wizard = prev.mutt-wizard.overrideAttrs (old: {
          src = prev.fetchFromGitHub {
            owner = "LukeSmithxyz";
            repo = "mutt-wizard";
            rev = "a8863a750a360bad6759f5f2c4df5d2001b31e18";
            hash = "sha256-8zPkzQ1Tt9t8G+uCKybBm4yMqfF2y4L7nmuaWWz9t6s=";
          };
        });
      })
    ];

    fonts.packages = lib.attrVals [
      "noto-fonts"
      "noto-fonts-emoji"
      "liberation_ttf"
      "ipafont"
    ] pkgs ++ builtins.filter lib.attrsets.isDerivation (builtins.attrValues pkgs.nerd-fonts);

    fonts.fontconfig.defaultFonts = {
      monospace = [
        "Noto Sans Mono"
        "IPAGothic"
      ];
      sansSerif = [
        "Noto Sans"
        "IPAPGothic"
      ];
      serif = [
        "Noto Serif"
        "IPAPMincho"
      ];
    };
  };
}