{ inputs, flake, self }:
{ config, pkgs, lib, ... }: let
  cfg = config.banned.services.dreamproxy-bot;
  system = pkgs.system;
in {
  options = {
    banned.services.dreamproxy-bot = {
      enable = lib.mkOption {
        type = lib.types.bool;
        default = false;
      };
      environmentPath = lib.mkOption {
        type = lib.types.path;
        example = ''
          config.sops.secrets."name-of-service/environment".path
        '';
        description = ''
          BOT_TOKEN=
          LIGHTNINGPROXIESAPI_KEY=
          ADMIN_ID=
          BACKUP_PATH=
          DATABASE_PATH=
          INTERVAL_HOURS=
          CRYSTALPAY_LOGIN=
          CRYSTALPAY_SECRET=
          CRYSTALPAY_SALT=
          HELEKET_MERCHANT=
          HELEKET_SIGN=
        '';
      };
    };
  };
  config = lib.mkIf cfg.enable {
    systemd.services.dreamproxy-bot = {
      description = "DreamProxy Bot Service";
      after = [ "network.target" ];
      wantedBy = [ "multi-user.target" ];
      serviceConfig = {
        Type = "simple";
        ExecStart = "${self.packages.${system}.dreamproxy-bot}/bin/dreamproxy-bot";
	EnvironmentFile = cfg.environmentPath;
        Restart = "always";
        RestartSec = "5s";
        
        # Shutdown configuration
        TimeoutStopSec = "30s";
        KillSignal = "SIGTERM";
        KillMode = "mixed";
        
        # Security and process management
        RemainAfterExit = false;
        StandardOutput = "journal";
        StandardError = "journal";
      };
    };
  };
}
