{ config, lib, ... }:

with lib;

let
  cfg = config.settings.containers.storage;
in {
  options = {
    settings.containers.storage.enable = lib.mkOption {
      type = lib.types.bool;
      default = false;
      description = ''
        Enable storage configuration
      '';
    };
  };

  config = mkIf cfg.enable {
    services.podman.containers.dufs = {
      image = "sigoden/dufs";
      network = "proxy";
      volumes = [
        "%h/storage:/data" 
      ];
      userNS = "keep-id";
      environment = {
        DUFS_SERVE_PATH = "data";
        DUFS_AUTH = "@/tboomers/public:ro|tboomers:password@/tboomers:rw";
        DUFS_ALLOW_ALL = true;
      };
    };

    services.podman.containers.syncthing = {
      image = "syncthing/syncthing";
      network = "proxy";
      volumes = [
        "%h/storage:/storage"
        "%h/containers/syncthing/data:/var/syncthing"   
      ];
      userNS = "keep-id";
      ports = [
        "22000:22000/tcp"
        "22000:22000/udp"
      ];
    };

    settings.containers.caddy.routes.tbmrs-local.routes.sycnthing = {
      host = "syncthing";
      url = "syncthing:8384"; 
    };

    settings.containers.caddy.routes.tbmrs.routes.dufs = {
      host = "files";
      url = "dufs:5000"; 
    };
  };
}
