{
  lib,
  config,
  ...
}: let
  inherit (lib) mkEnableOption mkIf;
  cfg = config.horseman.network.syncthing;
  username = config.horseman.username;
in {
  options = {
    horseman.network.syncthing = {
      enable = mkEnableOption "";
    };
  };

  config = mkIf cfg.enable {
    services.syncthing = {
      enable = true;
      user = username;
      group = "users";
      dataDir = "/home/${username}";
      configDir = "/home/${username}/.config/syncthing";
      overrideDevices = true;
      settings = {
        options = {
          urAccepted = -1;
        };
        devices = {
          "luna" = {
            id = "MW4ZTAX-D7KDLRL-YHNGNCF-V6FW5L4-SCKQKES-BO7KV43-L5667GL-JHIYEAA";
            autoAcceptFolders = true;
            name = "luna";
          };
          "artemis" = {
            id = "6YN6SF4-5EK3YZX-WN7S56S-MMTXVV6-LE4IVZR-6LZBTNY-LG4LDX5-4XGKQAB";
            autoAcceptFolders = true;
            name = "artemis";
          };
          "terra" = {
            id = "2QWRFLY-ZUY5C6C-X36R5CY-PJSGLYY-5HWIWJN-2YYWRPU-T66GJMU-GXTQ6QK";
            autoAcceptFolders = true;
            name = "terra";
          };
          "solis" = {
            id = "YOSYADZ-3OZ3XBH-7XEIK2W-DHAEIFD-5P5ZIHB-PAP74DH-T7GHLKT-O32YEA4";
            autoAcceptFolders = true;
            name = "solis";
          };
        };
        folders = {
          "Documents" = {
            id = "documentFolder";
            path = "/home/${username}/Documents";
            devices = ["artemis" "terra" "solis"];
          };
          "Programming" = {
            id = "programmingFolder";
            path = "/home/${username}/Programming";
            devices = ["artemis" "terra" "solis"];
            ignorePatterns = [
              "node_modules"
              ".venv"
              "venv"
              "dist-newstyle"
              "constipated-koala/storage"
            ];
          };
        };
      };
    };
    networking.firewall.allowedUDPPorts = [22000 21027];
    networking.firewall.allowedTCPPorts = [8384 22000];
  };
}
