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

let cfg = config.sydnix.users.crumb.anki;
in {
  options.sydnix.users.crumb.anki = {
    enable = lib.mkEnableOption "Anki desktop";
  };

  config = lib.mkIf cfg.enable {
    sydnix.impermanence.directories = [
      ".local/share/Anki2"
    ];

    sydnix.sops.secrets = {
      anki-sync-key = {};
      anki-username = {};
    };

    programs.anki = {
      enable = true;
      addons = with pkgs.ankiAddons; [
        review-heatmap
      ];
      sync = {
        autoSync = true;
        syncMedia = true;
        url = "https://anki.deertopia.net/";
        usernameFile = config.sops.secrets.anki-username.path;
        keyFile = config.sops.secrets.anki-sync-key.path;
      };
    };
  };
}
