local task(name) =
  {
    name: 'Configure ' + name,
    import_tasks: name + '.yml',
  }
  // Handle special cases
  + if std.member(['fuzzel', 'wofi', 'rofi'], name) then
    { tags: 'launcher', when: 'launcher == "' + name + '"' }
  else if std.member(['imv'], name) then
    { tags: name, when: 'image_viewer == "' + name + '"' }
  else if std.member(['fish', 'bash', 'nushell', 'xonsh'], name) then
    { tags: ['shells', name] }
  else if name == 'chromium' then
    { tags: name, become: true }
  else { tags: name }
;

local modules = [
  'aerc',
  'amfora',
  'animdl',
  'bash',
  'bat',
  'btop',
  'calcurse',
  'castero',
  'cava',
  'chromium',
  'element-desktop',
  'emacs',
  'fcitx5',
  'fish',
  'fontconfig',
  'fuzzel',
  'gallery-dl',
  'gdb',
  'git',
  'glow',
  'gnupg',
  'imv',
  'k9s',
  'lazygit',
  'luarocks',
  'lsd',
  'mimeapps',
  'mpd',
  'mpv',
  'newsboat',
  'notification',
  'npm',
  'nushell',
  'nvim',
  'pyradio',
  'ripgrep',
  'river',
  'rofi',
  'streamlink',
  'superd',
  'swappy',
  'sway',
  'translate-shell',
  'vifm',
  'waybar',
  'weechat',
  'wofi',
  'xdg-desktop-portal-wlr',
  'xonsh',
  'yt-dlp',
  'ytmdl',
  'zathura',
  'zellij',
];

std.manifestYamlDoc([
  {
    name: 'starship | Copy shell prompt config',
    tags: ['shells', 'starship'],
    copy: {
      src: 'starship.toml',
      dest: '{{ xdg_dir.config_home }}/starship.toml',
      mode: '644',
    },
  },
  {
    name: 'Configure terminal emulators',
    include_tasks: {
      file: '{{ item }}.yml',
      apply: {
        tags: ['terminal', '{{ item }}'],
      },
    },
    loop: '{{ terminal_emulators }}',
    // `tags` field doesn't allow variables so hardcode possible values here
    tags: ['terminal', 'foot', 'alacritty'],
  },
  {
    name: 'xdg-user-dirs | Configure XDG_USER_DIRS definitions',
    copy: {
      src: 'user-dirs.dirs',
      dest: '{{ xdg_dir.config_home }}/user-dirs.dirs',
      mode: '644',
    },
    tags: 'xdg-user-dirs',
  },
  {
    name: 'golang | Set telemetry to off',
    block: [
      {
        name: 'golang | Create Go config directory',
        file: {
          path: '{{ xdg_dir.config_home }}/go/telemetry',
          mode: '755',
          state: 'directory',
        },
      },
      {
        name: 'golang | Set mode file to off with current date',
        copy: {
          content: |||
            off {{ '%Y-%m-%d' | strftime }}
          |||,
          dest: '{{ xdg_dir.config_home }}/go/telemetry/mode',
          mode: '644',
        },
      },
    ],
    tags: ['gotelemetry', 'golang'],
  },
] + [task(x) for x in modules],
quote_keys=false)
