{ config, lib, inputs, outputs, pkgs, timeZone, system, ... }:
let
  supportedDesktops = [ "gnome" "hyprland" ];
  supportedDesktopsStr = lib.strings.concatStringsSep ", " supportedDesktops;
  deskCfg = config.deskCfg;
in
{
  options.deskCfg = {
      de = lib.mkOption {
          default = "";
          type = lib.types.str;
          description = "Desktop Environment";
      };
      userName = lib.mkOption {
          type = lib.types.str;
          description = "Main username for system";
      };
      hostName = lib.mkOption {
          type = lib.types.str;
          description = "Hostname for system";
      };
      installGaming = lib.mkOption {
          type = lib.types.bool;
          default = true;
          description = "Whether to install gaming software or not";
      };
  };

    imports = [
      modules/user/main_user.nix
    ];

   config = {
    assertions = [
      {
        assertion = builtins.elem deskCfg.de supportedDesktops;
        message = "Unsupported desktop environment: ${deskCfg.de}\nSupported DE's: ${supportedDesktopsStr}";
      }
    ];
  
    nixpkgs.overlays = [
      inputs.nur.overlays.default
    ];
  
 
    # Enable flakes feature
    nix.settings.experimental-features = [
      "nix-command" "flakes"
    ];
  
    # boot.plymouth.enable = true;
  
    boot = {
      plymouth = {
        enable = true;
        theme = "circle_flow";
        themePackages = with pkgs; [
          # By default we would install all themes
          (adi1090x-plymouth-themes.override {
            selected_themes = [ "circle_flow" ];
          })
        ];
      };

      # Enable "Silent Boot"
      consoleLogLevel = 0;
      initrd.verbose = false;
      kernelParams = [
        "quiet"
        "splash"
        "boot.shell_on_fail"
        "loglevel=3"
        "rd.systemd.show_status=false"
        "rd.udev.log_level=3"
        "udev.log_priority=3"
      ];
      # Hide the OS choice for bootloaders.
      # It's still possible to open the bootloader list by pressing any key
      # It will just not appear on screen unless a key is pressed
      loader.timeout = 0;
      # Use the systemd-boot EFI boot loader.
      loader.systemd-boot.enable = true;
      loader.efi.canTouchEfiVariables = true;
    };
    networking.hostName = deskCfg.hostName; # Define your hostname.
    networking.networkmanager.enable = true;  # Easiest to use and most distros use this by default.
    networking.wireless.iwd.enable = true;  

    time.timeZone = timeZone;
   
    main_user = {
      enable = true;
      userName = deskCfg.userName;
      isDesktopUser = true;
    };
    
    #niriwm = {
    #    enable = false;
    #    useNonFree = true;
    #    #installGaming = deskCfg.installGaming;
    #    systemPackages = with pkgs; [
    #      libreoffice
    #      rpi-imagergh
    #    ];
    #};

    ## TODO move all of this into a hyprland config
    environment.systemPackages = with pkgs; [
      cryptsetup
      nwg-hello
      cage
    ];
    # Get block UUID with
    # `sudo blkid /dev/mmcblk1p1`
    # Makes encrypted device available under /dev/mapper/enc_source
    environment.etc.crypttab.text = ''
      enc_source UUID=6e131a4e-1cba-4db7-b635-42381e4fd790 /root/keyfile
    '';
    programs.hyprland.enable = true;
    # programs.steam.enable = true;
    # For electron apps in wayland
    environment.sessionVariables.NIXOS_OZONE_WL = "1";

    services.greetd = {
      enable = true;
      settings = rec {
        initial_session = {
          command = "${pkgs.hyprland}/bin/hyprland";
          user = "scrappy";
        };
        default_session = initial_session;
      };
    };
    # For yubioath desktop
    services.pcscd.enable = true;
    # Audio
    security.rtkit.enable = true;
    services.pipewire = {
      enable = true;
      alsa.enable = true;
      pulse.enable = true;
      wireplumber.enable = true;
    };
    programs.thunar = {
        enable = true;
        plugins = with pkgs.xfce; [
            thunar-archive-plugin
            thunar-volman
        ];
    };
    programs.file-roller.enable = true;
    programs.xfconf.enable = true;
    # sound.enable = false;
    # services.xserver = {
    #   enable = true;
    #   displayManager.gdm.enable = true;
    #   desktopManager.gnome.enable = true;
    # };
    programs.regreet.enable = true;
   
    programs.zsh.enable = true;
    nixpkgs.config.allowUnfree = true;
    system.stateVersion = "24.05"; # Did you read the comment?
  };
}

