{
  config,
  lib,
  namespace,
  ...
}:
with lib;
let
  cfg = config.${namespace}.services.lubelogger;
in
{
  imports = [ ./options.nix ];

  config = mkIf cfg.enable {
    virtualisation.oci-containers.containers.lubelogger = {
      autoStart = true;
      image = "ghcr.io/hargata/lubelogger";
      ports = [ "${toString cfg.port}:8080" ];
      volumes = [
        "/media/nas/main/nix-app-data/lubelogger:/App/data"
        "/media/nas/main/nix-app-data/lubelogger/keys:/root/.aspnet/DataProtection-Keys"
      ];
      environmentFiles = [
        "/media/nas/main/nix-app-data/lubelogger/lubelogger.env"
      ];
      environment = {
        PUID = toString config.users.users.nix-apps.uid;
        PGID = toString config.users.groups.jallen-nas.gid;
        TZ = "America/Chicago";
      };
    };

    # Open firewall for lubelogger if enabled
    networking.firewall = mkIf cfg.openFirewall {
      allowedTCPPorts = [ cfg.port ];
      allowedUDPPorts = [ cfg.port ];
    };
  };
}
