#!/usr/bin/env bash

TOMBI_VERSION="0.9.22"
mise use -g tombi@$TOMBI_VERSION
TOMBI_LINT="mise x tombi@$TOMBI_VERSION -- tombi lint --offline --no-cache --error-on-warnings --quiet"
cat >"$HOME/tombi.toml" <<TOML
[schema]
enabled = true
strict = true
[[schemas]]
path = "file://$ROOT/schema/mise.json"
include = ["dot-prefix-valid.toml", "dot-prefix-invalid.toml"]
TOML
cat >dot-prefix-valid.toml <<'TOML'
[dotfiles]
"~" = { source = "home", mode = "symlink-each", dot_prefix = true, exclude = ["README.md"] }
"~/copied" = { source = "copied", mode = "copy", dot_prefix = true, manifest = "git" }
"~/.linked" = { source = "linked", mode = "symlink", dot_prefix = false }
# an omitted mode may resolve to dotfiles.default_mode = "symlink-each"
"~/implied" = { dot_prefix = true }
TOML
assert_succeed "$TOMBI_LINT dot-prefix-valid.toml"
for entry in \
  '{ source = "linked", mode = "symlink", dot_prefix = true }' \
  '{ source = "app.tera", mode = "template", dot_prefix = true }' \
  '{ content = "inline", dot_prefix = true }' \
  '{ permissions = "0600", dot_prefix = true }' \
  '{ mode = "track", dot_prefix = true }' \
  '{ mode = "absent", dot_prefix = true }'; do
  printf '[dotfiles]\n"~/.app" = %s\n' "$entry" >dot-prefix-invalid.toml
  assert_fail "$TOMBI_LINT dot-prefix-invalid.toml"
done
