{
  config,
  lib,
  namespace,
  ...
}:
with lib;
let
  cfg = config.${namespace}.services.immich;

  immichPort = 2283;
  dataDir = "/media/nas/main/photos";
  dbPassword = config.sops.secrets."jallen-nas/immich/db-password".path;
in
{
  imports = [ ./options.nix ];

  config = mkIf cfg.enable {
    # Enable immich service
    services.immich = {
      enable = true;
      port = immichPort;
      openFirewall = true;
      secretsFile = dbPassword;
      mediaLocation = dataDir;

      environment = {
        IMMICH_HOST = lib.mkForce "0.0.0.0";
        IMMICH_TRUSTED_PROXIES = "10.0.1.3";
        TZ = "America/Chicago";
      };

      machine-learning = {
        enable = true;
      };
    };
  };
}
