#!/bin/bash

# d0 command completion script for bash

_d0_completion() {
    local cur prev opts
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"

    # Available commands
    opts="init setup start hi connect tell list status info auth help version"

    # Available agents for tell/hi commands
    agents="president boss worker1 worker2 worker3 worker4 worker5 worker6 worker7 worker8 worker9 worker10 everyone"

    case "${prev}" in
        d0)
            COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
            return 0
            ;;
        tell|hi|connect)
            COMPREPLY=( $(compgen -W "${agents}" -- ${cur}) )
            return 0
            ;;
        init|setup)
            case "${cur}" in
                -*)
                    COMPREPLY=( $(compgen -W "--force --workers" -- ${cur}) )
                    return 0
                    ;;
            esac
            ;;
        --workers|-w)
            COMPREPLY=( $(compgen -W "1 2 3 4 5 6 7 8 9 10" -- ${cur}) )
            return 0
            ;;
        status)
            case "${cur}" in
                -*)
                    COMPREPLY=( $(compgen -W "--detailed" -- ${cur}) )
                    return 0
                    ;;
            esac
            ;;
        *)
            ;;
    esac

    # Default to no completion
    return 0
}

# Register the completion function
complete -F _d0_completion d0