# SPDX-FileCopyrightText: 2024 Clicks Codes
#
# SPDX-License-Identifier: GPL-3.0-only

{ lib, inputs, ... }: {
  nginx.http.internal = {
    generateWwwRedirects = hosts: let
      withWww = name: host: if host.www
        then {
          "${name}" = lib.attrsets.removeAttrs host [ "www" ];
          "www.${name}" = {
            routes."~ ^/?([^\r\n]*)$" = lib.home-manager.hm.dag.entryAnywhere (lib.clicks.nginx.http.redirectPermanent "https://${name}/$1");
            service = null;
            enableHttp = host.enableHttp;
            authWith = null;
          };
        }
        else {
          "${name}" = lib.attrsets.removeAttrs host [ "www" ];
        };
    in lib.pipe hosts [
      (lib.attrsets.mapAttrsToList withWww)
      (lib.lists.foldr (host: merged: merged // host) {})
    ];

    assertExactlyOneOfServiceOrRoutes = hosts: let
      validate = name: host: let
        routesProvided = host.routes != null && host.routes != {};
        serviceProvided = host.service != null;
      in
        if !serviceProvided && !routesProvided
        then builtins.throw "${name}: You must provide one of `service` or `routes`"
        else if serviceProvided && routesProvided
          then builtins.throw "${name}: You may only provide one of `service` or `routes`"
          else host;
    in lib.attrsets.mapAttrs validate hosts;

    assertTailscaleAuthServiceOnly = hosts: let
      validate = name: host:
        if host.authWith != "tailscale" || host.routes == null || host.routes == {}
        then host
        else builtins.throw "${name}: You may not use tailscale auth when manually specifying `routes`. Please use `service` instead";
    in lib.attrsets.mapAttrs validate hosts;

    translateServiceToRoutes = hosts: let
      validate = name: value:
        lib.trivial.throwIf (value.service != null && value.routes != null && value.routes != {}) "Both `service` and `routes` cannot be set at the same time" value;
      translate = name: value:
        lib.attrsets.removeAttrs (
          if (value.service != null)
          then value // {
            routes."/" = lib.home-manager.hm.dag.entryAnywhere value.service;
          }
          else value
        ) [ "service" ];
    in lib.attrsets.mapAttrs translate
      (lib.attrsets.mapAttrs validate hosts);

    translateRoutesDagToList = hosts: let
      hostTranslateRoutesDagToList = name: host: host // {
        routes = let
          HMDagRoutes = lib.home-manager.hm.dag.topoSort host.routes;
        in map ({name, data}: { inherit name; value = data; }) HMDagRoutes.result;
      };
    in lib.attrsets.mapAttrs hostTranslateRoutesDagToList hosts;

    unwrapHeaders = hosts: let
      unwrapHeader = route:
        if lib.types.isType "header" route.value
          then unwrapHeader {
            name = route.name;
            value = lib.attrsets.recursiveUpdate route.value.content {
              headers = (route.value.headers or {}) // {
                "${route.value.name}" = "${route.value.value}";
              };
            };
          }
          else route;

      hostUnwrapHeaders = name: host: host // {
        routes = lib.lists.forEach host.routes unwrapHeader;
      };
    in lib.attrsets.mapAttrs hostUnwrapHeaders hosts;

    translateRoutesToLocations = hosts: let
      addHeaderToLocation = header: location:
        location // {
          extraConfig = (location.extraConfig or "") + "\nadd_header \"${header.name}\" \"${header.value}\";";
        };
      addHeadersToLocation = headers: location:
        if headers == null
          then location
          else lib.trivial.pipe headers [
            lib.attrsets.attrsToList
            (lib.lists.foldr addHeaderToLocation location)
          ];
      serviceTypeHandlers = {
        directory = service: {
          root = service.root;
          index = "index.html index.htm";
          extraConfig = lib.strings.optionalString
            service.listContents
            "autoindex on;";
        };
        file = service: {
          root = "/";
          tryFiles = "${service.path} =404";
        };
        redirect = service: let
          statusCode =
            if service.permanent
            then "307"
            else "308";
        in {
          return = "${statusCode} ${service.to}";
        };
        reverseProxy = service: {
          proxyPass = "${service.protocol}://${service.host}:${builtins.toString service.port}";
          proxyWebsockets = true;
          recommendedProxySettings = true;
        };
        status = service: {
          return = builtins.toString service.statusCode;
        };
      };
      translateServiceToLocation = service: lib.trivial.pipe service.value [
        serviceTypeHandlers.${service.value._type}
        (addHeadersToLocation service.value.headers)
        (location: { name = service.name; value = location; })
      ];
      hostTranslateRoutesToLocations = name: host: lib.attrsets.removeAttrs (host // {
        locations = lib.lists.forEach host.routes translateServiceToLocation;
      }) [ "routes" ];
    in lib.attrsets.mapAttrs hostTranslateRoutesToLocations hosts;

    setLocationPriorities = hosts: let
      priorityByIndex = index: 100 + index * 50;
      locationWithPriority = index: location: {
        name = location.name;
        value = location.value // {
          priority = location.value.priority or priorityByIndex index;
        };
      };
      setHostLocationPriority = name: host: host // {
        locations = lib.pipe host.locations [
          (lib.lists.imap0 locationWithPriority)
          lib.attrsets.listToAttrs
        ];
      };
    in lib.attrsets.mapAttrs setHostLocationPriority hosts;

    addListenDefaults = hosts: let
      setDefaults = name: host: lib.attrsets.removeAttrs (host // {
        onlySSL = !host.enableHttp;
        addSSL = host.enableHttp;

        useACMEHost = name;
      }) [ "enableHttp" ];
    in lib.attrsets.mapAttrs setDefaults hosts;

    serviceTranslation = hosts: lib.trivial.pipe hosts [
      lib.clicks.nginx.http.internal.assertExactlyOneOfServiceOrRoutes
      lib.clicks.nginx.http.internal.assertTailscaleAuthServiceOnly
      lib.clicks.nginx.http.internal.generateWwwRedirects
      lib.clicks.nginx.http.internal.translateServiceToRoutes
      lib.clicks.nginx.http.internal.translateRoutesDagToList
      lib.clicks.nginx.http.internal.unwrapHeaders
      lib.clicks.nginx.http.internal.translateRoutesToLocations
      lib.clicks.nginx.http.internal.setLocationPriorities
      lib.clicks.nginx.http.internal.addListenDefaults
    ];
  };
}
