#compdef sc

autoload -U is-at-least

_sc_model() {
  local -a args
  sm=($(ollama list | awk '{ print $1 }' | tail -n+2))
  _wanted args expl 'sc model' compadd -S '' "$sm[@]"
}

_sc() {
  typeset -A opt_args
  typeset -a _arguments_options
  local ret=1

  if is-at-least 5.2; then
    _arguments_options=(-s -S -C)
  else
    _arguments_options=(-s -C)
  fi

  local context curcontext="$curcontext" state line
  _arguments "${_arguments_options[@]}" : \
    '(- :)-h' \
    '(- :)--help' \
    '(-e)--extend-conversation[whether to extend the previous conversation or start a new one]' \
    '(--extend-conversation)-e[whether to extend the previous conversation or start a new one]' \
    '(-r)--repeat-input[whether to repeat the input before the output, useful to extend instead of replacing]' \
    '(--repeat-input)-r[whether to repeat the input before the output, useful to extend instead of replacing]' \
    '(-a)--api[overrides which api to hit (possible values: ollama, anthropic, mistral, openai)]:api:' \
    '(--api)-a[overrides which api to hit (possible values: ollama, anthropic, mistral, openai)]:api:' \
    '(-m)--model[overrides which model (of the api) to use]:model:_sc_model' \
    '(--model)-m[overrides which model (of the api) to use]:model:_sc_model' \
    '(-t)--temperature[higher temperature  means answer further from the average]:temperature:' \
    '(--temperature)-t[higher temperature  means answer further from the average]:temperature:' \
    '(-l)--char-limit[max number of chars to include, ask for user approval if more, 0 = no limit]:char_limit:' \
    '(--char-limit)-l[max number of chars to include, ask for user approval if more, 0 = no limit]:char_limit:' \
    '(-c)--context[glob patterns or list of files to use the content as context make sure its the last arg]:context:' \
    '(--context)-c[glob patterns or list of files to use the content as context make sure its the last arg]:context:' \
    '(-v)--version[Print version]' \
    '*:file:_files' \
    && ret=0
}

if [ "$funcstack[1]" = "_sc" ]; then
  _sc "$@"
else
  compdef _sc sc
fi
