{ config, pkgs, lib, ... }: let 
  cfg = config.services.transmission-exporter; 
in {
  options.services.transmission-exporter = {
    enable = lib.mkEnableOption "enables transmission exporter";

    web_path = lib.mkOption {
      type = lib.types.str;
      default = "/metrics";
      description = "Path for metrics";
    };

    web_addr = lib.mkOption {
      type = lib.types.str;
      default = ":19091";
      description = "Address for this exporter to run";
    };

    transmission_addr = lib.mkOption {
      type = lib.types.str;
      default = "http://localhost:9091";
      description = "Transmission address to connect with";
    };

    transmission_username = lib.mkOption {
      type = lib.types.str;
      default = "";
      description = "Transmission username";
    };

    transmission_password = lib.mkOption {
      type = lib.types.str;
      default = "";
      description = "Transmission password";
    };
  };

  config = lib.mkIf cfg.enable {
    systemd.services.transmission-exporter = {
      enable = true;
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      description = "Transmission exporter for Prometheus";
      environment = {
        WEB_PATH = cfg.web_path;
        WEB_ADDR = cfg.web_addr;
        TRANSMISSION_ADDR = cfg.transmission_addr;
        TRANSMISSION_USERNAME = cfg.transmission_username;
        TRANSMISSION_PASSWORD = cfg.transmission_password;
      };
      serviceConfig = {
        Type = "simple";
        User = "nobody";
        Group = "nobody";
        Restart = "always";
        ExecStart = "${pkgs.local-pkgs.transmission-exporter}/bin/transmission-exporter";
        RuntimeDirectory = "transmission-exporter";
      };
    };
  };
}
