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

let cfg = config.sydnix.deertopia.servarr.prowlarr;
in {
  options.sydnix.deertopia.servarr.prowlarr = {
    enable = lib.mkEnableOption "Prowlarr (via Nixarr)";
  };

  config = lib.mkIf cfg.enable {
    nixarr.prowlarr = {
      enable = true;
      openFirewall = true;
    };

    sydnix.deertopia.nginx.vhosts."prowlarr" = {
      directory = null;
      vhost = {
        forceSSL = true;
        enableACME = true;
        extraConfig = ''
          # include ${../authelia/authelia-location.conf};
          set $upstream http://127.0.0.1:9696;
        '';
        locations."/".extraConfig = ''
          # include ${../authelia/authelia-authrequest.conf};
          # include ${../authelia/proxy.conf};
          proxy_pass $upstream;
        '';
      };
    };
  };
}
