[tools]
"aqua:flutter/flutter" = "3.44.1"
java = "21.0.2"

[tools."github:CQLabs/homebrew-dcm"]
version = "1.37.0"
bin = "dcm"
postinstall = "chmod +x \"$MISE_TOOL_INSTALL_PATH/dcm\" || true"

[tools."github:CQLabs/homebrew-dcm".platforms]
linux-x64 = { asset_pattern = "dcm-linux-x64-release.zip" }
linux-arm64 = { asset_pattern = "dcm-linux-arm-release.zip" }
macos-x64 = { asset_pattern = "dcm-macos-x64-release.zip" }
macos-arm64 = { asset_pattern = "dcm-macos-arm-release.zip" }
windows-x64 = { asset_pattern = "dcm-windows-release.zip" }

[tasks."codegen:dart"]
alias = "codegen"
description = "Execute build_runner to auto-generate dart code"
sources = [
  "pubspec.yaml",
  "build.yaml",
  "lib/**/*.dart",
  "infrastructure/**/*.drift",
]
outputs = { auto = true }
run = [
  "dart run build_runner build --delete-conflicting-outputs",
  "dart format lib/routing/router.gr.dart",
]

[tasks."codegen:watch"]
alias = "watch"
description = "Watch and auto-generate dart code"
run = "dart run build_runner watch --delete-conflicting-outputs"

[tasks."codegen:pigeon"]
alias = "pigeon"
description = "Generate pigeon platform code"
run = [
  "ls pigeon/*.dart | xargs -n1 -P4 -I{} dart run pigeon --input {}",
  "dart format lib/platform/",
]

[tasks."codegen:translation"]
alias = "translation"
description = "Generate translations from i18n JSONs"
run = [
  { task = "//:i18n:format-fix" },
  { tasks = [
    "i18n:loader",
    "i18n:keys",
  ] },
]

[tasks."codegen:app-icon"]
description = "Generate app icons"
run = "flutter pub run flutter_launcher_icons:main"

[tasks."codegen:splash"]
description = "Generate splash screen"
run = "flutter pub run flutter_native_splash:create"

[tasks.test]
description = "Run mobile tests"
run = "flutter test"

[tasks.analyze]
alias = "lint"
description = "Analyze Dart code"
depends = ["analyze:dart", "analyze:dcm"]

[tasks."analyze-fix"]
alias = "lint-fix"
description = "Auto-fix Dart code"
depends = ["analyze-fix:dart", "analyze-fix:dcm"]

[tasks.format]
description = "Format Dart code"
run = "dart format --set-exit-if-changed $(find lib -name '*.dart' -not \\( -name '*.g.dart' -o -name '*.drift.dart' -o -name '*.gr.dart' \\))"

[tasks."build:android"]
description = "Build Android release"
run = "flutter build appbundle"

[tasks."drift:migration"]
alias = "migration"
description = "Generate database migrations"
run = "dart run drift_dev make-migrations"

[tasks.install]
alias = "install"
description = "Install flutter dependencies"
run = "flutter pub get"

[tasks.start]
alias = "start"
description = "Start flutter app"
run = "flutter run"

# Internal tasks
[tasks."i18n:loader"]
description = "Generate i18n loader"
hide = true
run = [
  "dart run easy_localization:generate -S ../i18n",
  "dart format lib/generated/codegen_loader.g.dart",
]

[tasks."i18n:keys"]
description = "Generate i18n keys"
hide = true
run = [
  "dart run bin/generate_keys.dart",
  "dart format lib/generated/translations.g.dart",
]

[tasks."analyze:dart"]
description = "Run Dart analysis"
hide = true
run = "dart analyze --fatal-infos"

[tasks."analyze:dcm"]
description = "Run Dart Code Metrics"
hide = true
run = "dcm analyze lib --fatal-style --fatal-warnings"

[tasks."analyze-fix:dart"]
description = "Auto-fix Dart analysis"
hide = true
run = "dart fix --apply"

[tasks."analyze-fix:dcm"]
description = "Auto-fix Dart Code Metrics"
hide = true
run = "dcm fix lib"


[tasks.checklist]
run = [
  { task = "codegen:pigeon" },
  { task = "codegen:dart" },
  { task = "codegen:translation" },
  { task = "analyze" },
  { task = "format" },
  { task = "test" },
]
