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

{
  programs.vdirsyncer.enable = true;
  accounts.contact = {
    basePath = ".contact";
    accounts = let
      calendarAccounts = config.accounts.calendar.accounts;
      local = {
        type = "filesystem";
        fileExt = ".vcf";
      };
    in {
      nextcloud = {
        inherit local;
        remote = {
          inherit (calendarAccounts.nextcloud.remote) userName passwordCommand;
          type = "carddav";
          url =
            "https://cloud.xenia.me.uk/remote.php/dav/addressbooks/users/xenia/contacts-1/";
        };
        vdirsyncer = {
          inherit (calendarAccounts.nextcloud.vdirsyncer) enable;
          collections = [ "from a" ];
        };
      };
      # Remove for now as contact syncing doesn't seem to work with davmail
      # TODO investigate LDAP based solution instead
      # ukaea = {
      #   inherit local;
      #   remote = rec {
      #     inherit (calendarAccounts.ukaea.remote) userName passwordCommand;
      #     type = "carddav";
      #     url = "http://localhost:1080/users/${userName}/contacts/";
      #   };
      #   vdirsyncer = {
      #     inherit (calendarAccounts.ukaea.vdirsyncer) enable;
      #     collections = [ "contacts" ];
      #   };
      # };
    };
  };
}