{ lib, ... }:
let
  inherit (lib) mkEnableOption mkOption types;

  syncType = types.submodule ({ ... }: {
    options = {
      remotePath = mkOption {
        type = types.str;
        description = "The path to the folder on the cloud to sync.";
      };

      localPath = mkOption {
        type = types.str;
        description = "The path to sync the cloud content to.";
      };

      virtualFiles = (mkEnableOption "virtual file support") // {
        default = true;
      };
    };
  });

  commonOptions = {
    enable = mkEnableOption "Nextcloud client";
  };

  userOptions = {
    folderSyncs = mkOption {
      type = types.listOf syncType;
      description = "The folders to synchronize";
      default = [ ];
    };
  };
in
{
  options = {
    valhalla = {
      programs.nextcloud = commonOptions;

      users = mkOption {
        type = types.attrsOf (types.submodule (
          { ... }: {
            options = {
              programs.nextcloud = commonOptions;
            };
          }
        ));
      };

      windows.users = mkOption {
        type = types.attrsOf (types.submodule (
          { ... }: {
            options = {
              programs.nextcloud = userOptions;
            };
          }
        ));
      };
    };
  };
}