{ lib, config, ... }:
let
  cfg = config.apps.openfga;
  env = config.apps.env;

  values = lib.apps.appValues {
    inherit env;
    base = ../values/openfga;
    extraValues = {};
  };

  kustomize = r:
    if r.kind == "Job" then
      lib.attrsets.recursiveUpdate r { spec.backoffLimit = 2; }
    else r;

in
  {
    options.apps.openfga = lib.apps.appOptions {};

    config = lib.apps.appConfig cfg "${env}-openfga" {
        helm.releases."${env}-openfga" = {
          inherit values;
          chart = lib.helm.downloadHelmChart {
            repo = "https://openfga.github.io/helm-charts";
            chart = "openfga";
              version = "0.2.12";
              chartHash = "sha256-7yLcw9/oNPvCePrtTJwKAG88t0Ym5Dl/S83Gz+gQdDU=";
          };
          transformer = rs: builtins.map (x: kustomize x) rs;
        };

        annotations = {};
        resources = {
          services.poop.spec = {
          };
        };
      };
  }
