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

with lib;

let
  cfg = config.roles.desktop;
in
{
  options.roles.desktop.steamos = {
    enable = mkEnableOption "SteamOS (Jovian) configuration";

    autoStart = mkOption {
      type = types.bool;
      default = false;
      description = "Automatically start Steam Deck UI on boot";
    };

    user = mkOption {
      type = types.str;
      default = "johno";
      description = "User to run Steam as";
    };

    desktopSession = mkOption {
      type = types.nullOr types.str;
      default = null;
      description = "Desktop session to launch when switching to Desktop Mode";
    };

    enableDeckyLoader = mkOption {
      type = types.bool;
      default = true;
      description = "Enable Decky Loader plugin system";
    };
  };

  config = mkIf (cfg.enable && cfg.steamos.enable) {
    jovian.steam = {
      enable = true;
      autoStart = cfg.steamos.autoStart;
      user = cfg.steamos.user;
      desktopSession = cfg.steamos.desktopSession;
    };

    jovian.decky-loader.enable = cfg.steamos.enableDeckyLoader;

    environment.systemPackages = with pkgs; [
      maliit-keyboard
    ];
  };
}
