{
  flake,
  lib,
  pkgs,
  ...
}:
let
  matchHelper = trigger: replace: {
    trigger = trigger;
    replace = replace;
  };
  configPath = ./config;

  configs = {
    url = { inherit flake matchHelper; };
    logic = { inherit matchHelper; };
    debate = { inherit matchHelper; };
    characters = { inherit matchHelper; };
    academic = { inherit matchHelper; };
    numbers = { inherit matchHelper; };
    email = { inherit flake matchHelper; };
  };

  baseMatches = {
    matches = lib.concatMap (name: import (configPath + "/${name}.nix") configs.${name}) (
      builtins.attrNames configs
    );
  };
in
{
  services.espanso = {
    enable = true;
    configs = {
      default = {
        pre_paste_delay = 0;
        show_notifications = false;
      };
    };
    package = pkgs.espanso-wayland;
    matches = {
      base = baseMatches;
      global_vars = {
        global_vars = [
          {
            name = "currentdate";
            type = "date";
            params = {
              format = "%d/%m/%Y";
            };
          }
          {
            name = "currenttime";
            type = "date";
            params = {
              format = "%R";
            };
          }
        ];
      };
    };
  };
}
