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

with lib;

let
  cfg = config.settings.applications.thunderbird;
in {
  options = {
    settings.applications.thunderbird.enable = lib.mkOption {
      type = lib.types.bool;
      description = ''
        Enable thunderbird mail
      '';
    };
  };

  config = mkIf cfg.enable {
   	programs.thunderbird = {
      enable = true;
      package = pkgs.unstable.thunderbird;
      profiles = {
        default = {
          isDefault = true;  
        };
      };
    };

    accounts.email.accounts = {
      ziggo = {
        imap = {
          host = "imap.ziggo.nl";
          port = 993;
          tls = {
            enable = true;
          };
        };
        smtp =  {
          host = "smtp.ziggo.nl";
          port = 587;
          tls = {
            enable = true;
            useStartTls = true;
          };
        };
        address = "timo.boomers@ziggo.nl";
        realName = "Timo Boomers";
        userName = "timo.boomers@ziggo.nl";
        primary = true;
        thunderbird.enable = true;
        thunderbird.profiles = [ "default" ];
      };
      tudelft = {
        imap = {
          host = "outlook.office365.com";
          port = 993;
          tls = {
            enable = true;
          };
        };
        smtp =  {
          host = "smtp.office365.com";
          port = 587;
          tls = {
            enable = true;
            useStartTls = false;
          };
        };
        address = "tboomers@tudelft.nl";
        realName = "Timo Boomers";
        userName = "tboomers@tudelft.nl";
        primary = false;
        thunderbird.enable = true;
        thunderbird.profiles = [ "default" ];
      };
      xeovalyte = {
        imap = {
          host = "mail.xeovalyte.dev";
          port = 993;
          tls = {
            enable = true;
          };
        };
        smtp =  {
          host = "mail.xeovalyte.dev";
          port = 587;
          tls = {
            enable = true;
            useStartTls = true;
          };
        };
        address = "timo@xeovalyte.dev";
        aliases = [ "me@xeovalyte.dev" "contact@xeovalyte.dev" ];
        realName = "Timo Boomers";
        userName = "me@xeovalyte.dev";
        primary = false;
        thunderbird.enable = true;
        thunderbird.profiles = [ "default" ];
      };
    };
  };
}
