{ self, flake, inputs }:
{ config, lib, pkgs, ... }:
let
  system = pkgs.system;
  cfg    = config.banned.services.photoedit-bot;
  adminListStr = lib.concatStringsSep "," (map toString cfg.adminList);
in
{
  options = {
    banned.services.photoedit-bot = {
      enable = lib.mkEnableOption "enable photoedit-bot";
      adminList = lib.mkOption {
        type = lib.types.listOf lib.types.int;
        default = [];
        description = "List telegram api ids";
      };
      environmentPath = lib.mkOption {
        type = lib.types.path;
        example = ''
          config.sops.secrets."name-of-service/environment".path
        '';
        description = ''
          DATABASE_URL=
          TOKEN=
        '';
      };
    };
  };
  config = lib.mkIf cfg.enable {
    systemd.services.photoedit-bot =
    {
      wantedBy      = ["default.target"];
      after         = ["network-online.target"];
      requires      = ["network-online.target"];
      serviceConfig = {
        EnvironmentFile = cfg.environmentPath;
        Environment = [
          "LOG_LEVEL=DEBUG"
	  "ADMIN_LIST=${adminListStr}"
	];
        ExecStart   = "${self.packages.${system}.photoedit-bot}/bin/photoedit-bot";
      };
    };
    system.activationScripts.photoedit-bot =
    {
      text = ''
        mkdir -p /root/photoedit/source_dir
        cp -r ${flake}/package/photoedit-bot/source_dir/* /root/photoedit/source_dir/
      '';
    };
  };
}
