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

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

  config = lib.mkIf cfg.enable {
    sydnix.sops.secrets.transmission-credentials = {
      owner = config.services.transmission.user;
      group = config.services.transmission.group;
      mode = "700";
    };

    nixarr.transmission = {
      enable = true;
      vpn.enable = true;
      credentialsFile = "/run/secrets/transmission-credentials";
      # Default (9091) conflicts with Authelia.
      uiPort = 7052;
    };
  };
}
