# Natera-specific environment and tooling
# Sourced last from .zshrc on Natera machines (when this file is present).
# All Natera config lives here only.

# PATH for Natera/Claude tooling
export PATH="$HOME/.local/bin:$PATH"

# Claude Code (Bedrock)
export CLAUDE_CODE_USE_BEDROCK=1
# export AWS_REGION=us-west-2
export ANTHROPIC_SMALL_FAST_MODEL_AWS_REGION=us-west-2
export ANTHROPIC_SMALL_FAST_MODEL=global.anthropic.claude-haiku-4-5-20251001-v1:0
export CLAUDE_CODE_ENABLE_TELEMETRY=1

# Primary model (what Claude Code uses by default)
export ANTHROPIC_MODEL='us.anthropic.claude-opus-5'
# Family pins (used by /model and for subagents)
export ANTHROPIC_DEFAULT_OPUS_MODEL='us.anthropic.claude-opus-5[1m]'
export ANTHROPIC_DEFAULT_SONNET_MODEL='us.anthropic.claude-sonnet-5[1m]'
export ANTHROPIC_DEFAULT_HAIKU_MODEL='us.anthropic.claude-haiku-4-5-20251001-v1:0'

export CLAUDE_CODE_USE_MANTLE=1
export AWS_REGION=us-east-1

# Raise the default 64000 output cap (helpful on Opus 4.7)
export CLAUDE_CODE_MAX_OUTPUT_TOKENS=128000
# Request a 1-hour prompt cache TTL instead of the 5-minute default.
# Good for long-lived sessions; writes are billed at a higher rate.
#export ENABLE_PROMPT_CACHING_1H=1

# OpenTelemetry (Natera staging)
export OTEL_METRICS_EXPORTER=otlp
export OTEL_EXPORTER_OTLP_PROTOCOL=http/protobuf
export OTEL_RESOURCE_ATTRIBUTES="user.email=$USER@natera.com"

# Jellyfish AI reporting — endpoint + bearer token live in zshrc-natera.private
# (sourced last, so its protocol/endpoint overrides take effect). See the
# Jellyfish block in zshrc-natera.private.example for the shape.

# Project-specific aliases
alias workbench='cd ~/work/rosalis'
alias core='cd ~/work/yalp-core'
alias histo='cd ~/work/yalp-histology'
alias pipeline='cd ~/work/yalp-pipeline-integration'
alias assayapi='cd ~/work/yalp-assay-qc-api'
alias assay='cd ~/work/yalp-assay-qc'
alias lvsync='cd ~/work/yalp-lv-sync'

# YALP Core development aliases
alias yalp:db:password='core && yalp-db-pw-dev | pbcopy'
alias yalp:db:rebuild='core && make local_db_destroy && make local_db_init && make local_db_start'
alias yalp:db:start='core && make local_db_start'
alias yalp:db:stop='core && make local_db_stop'
alias yalp:api='core && make local_run_api'
alias yalp:psql='core && docker exec -it yalp-core-postgres psql -U postgres -d yalp_core_db'
alias yalp:start='core && make local_db_start && make local_run_api'

# YALP Core perf testing — close all boring tunnels, kill stale API, start perf DB + API (backgrounded)
alias yalp:perf='core && boring list 2>/dev/null | tail -n +2 | awk "{print \$2}" | while read -r t; do boring close "$t" 2>/dev/null; done; lsof -ti :9258 | xargs kill 2>/dev/null; make local_container_db && make local_perf_db_start && make local_perf_run_api &>/dev/null & echo "YALP Core perf API starting on :9258 (pid $!)"'
alias yalp:perf:stop='lsof -ti :9258 | xargs kill 2>/dev/null && echo "YALP Core perf API stopped" || echo "No process on :9258"'

# Sync knowledgebase docs from all ~/work projects into ~/work/knowledgebases
sync-knowledgebases() {
  local src_base="$HOME/work"
  local dest_base="$HOME/work/knowledgebases"
  mkdir -p "$dest_base"
  for dir in "$src_base"/*/docs/knowledgebase; do
    [[ -d "$dir" ]] || continue
    local project="${dir%/docs/knowledgebase}"
    project="${project##*/}"
    echo "Syncing $project..."
    rm -rf "$dest_base/$project"
    cp -R "$dir" "$dest_base/$project"
  done
  echo "Done."
}
alias kb-sync='sync-knowledgebases'

# Natera repos use master as primary; rewrite "git switch main" to "git switch master"
git() {
  if [[ "$1" == "switch" && "${2:-}" == "main" ]]; then
    command git switch master "${@:3}"
  else
    command git "$@"
  fi
}

# Sensitive values (AWS profile, OTEL endpoint, cert paths, refresh alias) are in zshrc-natera.private
# Copy zshrc-natera.private.example to zshrc-natera.private and fill in. That file is gitignored.
[[ -f ~/dotfiles/zshrc-natera.private ]] && source ~/dotfiles/zshrc-natera.private
