{ pkgs, lib, config, ... }:
let
  cfg = config.mods.server.chat;
  port = config.mods.server.nginx.ports.chat;
in with lib; {
  options.mods.server = {
    chat = {
      enable = mkEnableOption {
        default = false;
        description = "enables ollama server";
      };
    };
  };

  config = mkIf cfg.enable {
    services.ollama = {
      enable = true;
      loadModels = [
        "deepseek-r1:1.5b"
        "deepseek-r1:7b"
        "deepseek-r1:8b"
        "gemma2:2b"
        "gemma2:9b"
      ];

    };

    services.open-webui = {
      enable = true;
      host = "0.0.0.0";

      environment = {
        ANONYMIZED_TELEMETRY = "False";
        DO_NOT_TRACK = "True";
        SCARF_NO_ANALYTICS = "True";
        OLLAMA_API_BASE_URL = "http://127.0.0.1:11434";
        # Disable authentication
        # WEBUI_AUTH = "False";
      };

      inherit port;
    };
  };
}
