{
  lib,
  config,
  pkgs,
  ...
}: let
  inherit (lib) mkEnableOption mkIf;
  cfg = config.horseman.timers.rooms;
in {
  options = {
    horseman.timers.rooms = {
      enable = mkEnableOption "Runs a script to search for student housing";
    };
  };

  config = mkIf cfg.enable {
    environment.systemPackages = with pkgs; [
      jdk
    ];

    systemd.timers."rooms" = {
      wantedBy = ["timers.target"];
      timerConfig = {
        OnCalendar = "*-*-* 23:00:00"; # Every day at 23:00
        Persistent = true;
      };
    };

    systemd.services."rooms" = {
      script = ''
        cd /home/horseman/scripts
        /run/current-system/sw/bin/java -jar KamerZoeken-1.0.0.jar headless
      '';
      serviceConfig = {
        Type = "oneshot";
        User = "root";
      };
    };
  };
}
