{
  config,
  lib,
  namespace,
  ...
}:
with lib;
let
  cfg = config.${namespace}.services.arrs;
in
{
  imports = [ ./options.nix ];

  config = mkIf cfg.enable {
    # Enable radarr service
    services.radarr = {
      enable = cfg.radarr.enable;
      openFirewall = true;
      user = "nix-apps";
      group = "jallen-nas";
      dataDir = cfg.radarr.dataDir;
    };

    # Enable Sonarr service
    services.sonarr = {
      enable = cfg.sonarr.enable;
      openFirewall = true;
      user = "nix-apps";
      group = "jallen-nas";
      dataDir = cfg.sonarr.dataDir;
    };

    # Enable Sabnzbd service
    services.sabnzbd = {
      enable = cfg.sabnzbd.enable;
      # openFirewall = true;
      user = "nix-apps";
      group = "jallen-nas";
      configFile = "${cfg.sabnzbd.dataDir}/sabnzbd.ini";
    };

    services.deluge = {
      enable = cfg.deluge.enable;
      user = "nix-apps";
      group = "jallen-nas";
      openFirewall = true;
      dataDir = "/media/nas/main";
      web = {
        enable = true;
        port = cfg.deluge.port;
        openFirewall = true;
      };
    };

    services.jackett = {
      enable = cfg.jackett.enable;
      user = "nix-apps";
      group = "jallen-nas";
      openFirewall = true;
    };
  };
}
