{
  config,
  lib,
  namespace,
  ...
}:
with lib;
let
  name = "jellyseerr";
  cfg = config.${namespace}.services.${name};

  jellyseerrConfig = lib.${namespace}.mkModule {
    inherit config name;
    description = "jellyseerr";
    options = { };
    moduleConfig = {
      # Enable jellyseerr service
      services.jellyseerr = {
        enable = true;
        port = cfg.port;
        openFirewall = cfg.openFirewall;
        configDir = "${cfg.configDir}/jellyseerr";
      };

      systemd.services = {
        jellyseerr = {
          serviceConfig = {
            WorkingDirectory = lib.mkForce "${cfg.configDir}/jellyseerr";
            StateDirectory = lib.mkForce "${cfg.configDir}/jellyseerr";
            StateDirectoryMode = lib.mkForce 700;
            DynamicUser = lib.mkForce false;
            ProtectSystem = lib.mkForce null;
          };
        };
      };
    };
  };
in
{
  imports = [ jellyseerrConfig ];
}
