#compdef fslog

autoload -U is-at-least

_fslog() {
    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[@]}" : \
'--dir=[Log directory]:DIR:_files' \
'--color=[Color output\: auto, always, never]:COLOR:(auto always never)' \
'--pager[Pipe output through a pager (\`\$FSLOG_PAGER\`, default \`less -RFX\`)]' \
'--less[Pipe output through a pager (\`\$FSLOG_PAGER\`, default \`less -RFX\`)]' \
'-h[Print help]' \
'--help[Print help]' \
'-V[Print version]' \
'--version[Print version]' \
":: :_fslog_commands" \
"*::: :->fslog" \
&& ret=0
    case $state in
    (fslog)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:fslog-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
&& ret=0
;;
(search)
_arguments "${_arguments_options[@]}" : \
'--from=[Start date (progressive tab-complete from filenames)]:FROM:_default' \
'--until=[End date (progressive tab-complete from filenames)]:UNTIL:_default' \
'(--from --until)--on=[A single date, shorthand for --from DATE --until DATE]:DATE:_default' \
'-A+[Lines of context to show after each match]:N:_default' \
'--after-context=[Lines of context to show after each match]:N:_default' \
'-B+[Lines of context to show before each match]:N:_default' \
'--before-context=[Lines of context to show before each match]:N:_default' \
'-C+[Lines of context before and after each match (sets both -A and -B)]:N:_default' \
'--context=[Lines of context before and after each match (sets both -A and -B)]:N:_default' \
'*-u+[UUID substring filter (case-insensitive, repeatable, OR logic)]:UUID:_default' \
'*--uuid=[UUID substring filter (case-insensitive, repeatable, OR logic)]:UUID:_default' \
'-l+[Minimum log level]:LEVEL:_default' \
'--level=[Minimum log level]:LEVEL:_default' \
'*-c+[Message category filter (repeatable, OR logic)]:KIND:_default' \
'*--category=[Message category filter (repeatable, OR logic)]:KIND:_default' \
'--fgrep=[Fixed string substring search (case-insensitive)]:PATTERN:_default' \
'--grep=[Regex pattern search]:PATTERN:_default' \
'*--codec=[Codec name in a negotiation or SDP block (repeatable, OR logic)]:NAME:_default' \
'*--file=[Explicit files to scan (overrides --from/--until auto-discovery)]:FILE:_files' \
'(--from --until --on)--today[Today only, in the machine'\''s local timezone]' \
'-y[Skip confirmation prompt for large file sets]' \
'--yes[Skip confirmation prompt for large file sets]' \
'--related[Expand to bridged/transferred peer legs of matching sessions]' \
'--match-blocks[Also match --fgrep/--grep/PATTERN inside attached block lines (SDP, CHANNEL_DATA)]' \
'--blocks[Expand structured blocks inline (CHANNEL_DATA fields/variables, SDP bodies, codec negotiation)]' \
'--session[Annotate entries with tracked session state (dialplan context, channel state, channel name)]' \
'--stats[Summary only, no per-entry output]' \
'--unclassified[Report unclassified lines]' \
'-n[Show line numbers in output]' \
'--line-numbers[Show line numbers in output]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'::pattern -- Fixed-string pattern (case-insensitive); shorthand for --fgrep:_default' \
&& ret=0
;;
(read)
_arguments "${_arguments_options[@]}" : \
'*-u+[UUID substring filter (case-insensitive, repeatable, OR logic)]:UUID:_default' \
'*--uuid=[UUID substring filter (case-insensitive, repeatable, OR logic)]:UUID:_default' \
'-l+[Minimum log level]:LEVEL:_default' \
'--level=[Minimum log level]:LEVEL:_default' \
'*-c+[Message category filter (repeatable, OR logic)]:KIND:_default' \
'*--category=[Message category filter (repeatable, OR logic)]:KIND:_default' \
'--fgrep=[Fixed string substring search (case-insensitive)]:PATTERN:_default' \
'--grep=[Regex pattern search]:PATTERN:_default' \
'*--codec=[Codec name in a negotiation or SDP block (repeatable, OR logic)]:NAME:_default' \
'--match-blocks[Also match --fgrep/--grep/PATTERN inside attached block lines (SDP, CHANNEL_DATA)]' \
'--blocks[Expand structured blocks inline (CHANNEL_DATA fields/variables, SDP bodies, codec negotiation)]' \
'--session[Annotate entries with tracked session state (dialplan context, channel state, channel name)]' \
'--stats[Summary only, no per-entry output]' \
'--unclassified[Report unclassified lines]' \
'-n[Show line numbers in output]' \
'--line-numbers[Show line numbers in output]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'::file -- Log file to read (default\: freeswitch.log in --dir, or stdin if `-`):_default' \
&& ret=0
;;
(tail)
_arguments "${_arguments_options[@]}" : \
'*-u+[UUID substring filter (case-insensitive, repeatable, OR logic)]:UUID:_default' \
'*--uuid=[UUID substring filter (case-insensitive, repeatable, OR logic)]:UUID:_default' \
'-l+[Minimum log level]:LEVEL:_default' \
'--level=[Minimum log level]:LEVEL:_default' \
'*-c+[Message category filter (repeatable, OR logic)]:KIND:_default' \
'*--category=[Message category filter (repeatable, OR logic)]:KIND:_default' \
'--fgrep=[Fixed string substring search (case-insensitive)]:PATTERN:_default' \
'--grep=[Regex pattern search]:PATTERN:_default' \
'*--codec=[Codec name in a negotiation or SDP block (repeatable, OR logic)]:NAME:_default' \
'--lines=[Number of recent lines to show initially]:LINES:_default' \
'--match-blocks[Also match --fgrep/--grep/PATTERN inside attached block lines (SDP, CHANNEL_DATA)]' \
'--blocks[Expand structured blocks inline (CHANNEL_DATA fields/variables, SDP bodies, codec negotiation)]' \
'--session[Annotate entries with tracked session state (dialplan context, channel state, channel name)]' \
'--stats[Summary only, no per-entry output]' \
'--unclassified[Report unclassified lines]' \
'-n[Show line numbers in output]' \
'--line-numbers[Show line numbers in output]' \
'-h[Print help (see more with '\''--help'\'')]' \
'--help[Print help (see more with '\''--help'\'')]' \
'::file -- Log file to tail (default\: freeswitch.log in --dir):_default' \
&& ret=0
;;
(monitor)
_arguments "${_arguments_options[@]}" : \
'--config=[Config file path]:CONFIG:_files' \
'--context=[Filter by dialplan context (comma-separated, prefix with - to exclude)]:CTX:_default' \
'--dump[Print call table to stdout and exit (no TUI)]' \
'-h[Print help]' \
'--help[Print help]' \
'::file -- Log file to tail (default\: freeswitch.log in --dir):_default' \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
'-h[Print help]' \
'--help[Print help]' \
':shell -- Shell to generate completions for:(bash elvish fish powershell zsh)' \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
":: :_fslog__subcmd__help_commands" \
"*::: :->help" \
&& ret=0

    case $state in
    (help)
        words=($line[1] "${words[@]}")
        (( CURRENT += 1 ))
        curcontext="${curcontext%:*:*}:fslog-help-command-$line[1]:"
        case $line[1] in
            (list)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(search)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(read)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(tail)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(monitor)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(completions)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
(help)
_arguments "${_arguments_options[@]}" : \
&& ret=0
;;
        esac
    ;;
esac
;;
        esac
    ;;
esac
}

(( $+functions[_fslog_commands] )) ||
_fslog_commands() {
    local commands; commands=(
'list:List log files with dates and sizes' \
'search:Search/filter entries across multiple files' \
'read:Parse and display a single log file' \
'tail:Follow the log file and display new entries in color' \
'monitor:Live TUI dashboard of active calls' \
'completions:Generate shell completion script' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'fslog commands' commands "$@"
}
(( $+functions[_fslog__subcmd__completions_commands] )) ||
_fslog__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'fslog completions commands' commands "$@"
}
(( $+functions[_fslog__subcmd__help_commands] )) ||
_fslog__subcmd__help_commands() {
    local commands; commands=(
'list:List log files with dates and sizes' \
'search:Search/filter entries across multiple files' \
'read:Parse and display a single log file' \
'tail:Follow the log file and display new entries in color' \
'monitor:Live TUI dashboard of active calls' \
'completions:Generate shell completion script' \
'help:Print this message or the help of the given subcommand(s)' \
    )
    _describe -t commands 'fslog help commands' commands "$@"
}
(( $+functions[_fslog__subcmd__help__subcmd__completions_commands] )) ||
_fslog__subcmd__help__subcmd__completions_commands() {
    local commands; commands=()
    _describe -t commands 'fslog help completions commands' commands "$@"
}
(( $+functions[_fslog__subcmd__help__subcmd__help_commands] )) ||
_fslog__subcmd__help__subcmd__help_commands() {
    local commands; commands=()
    _describe -t commands 'fslog help help commands' commands "$@"
}
(( $+functions[_fslog__subcmd__help__subcmd__list_commands] )) ||
_fslog__subcmd__help__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'fslog help list commands' commands "$@"
}
(( $+functions[_fslog__subcmd__help__subcmd__monitor_commands] )) ||
_fslog__subcmd__help__subcmd__monitor_commands() {
    local commands; commands=()
    _describe -t commands 'fslog help monitor commands' commands "$@"
}
(( $+functions[_fslog__subcmd__help__subcmd__read_commands] )) ||
_fslog__subcmd__help__subcmd__read_commands() {
    local commands; commands=()
    _describe -t commands 'fslog help read commands' commands "$@"
}
(( $+functions[_fslog__subcmd__help__subcmd__search_commands] )) ||
_fslog__subcmd__help__subcmd__search_commands() {
    local commands; commands=()
    _describe -t commands 'fslog help search commands' commands "$@"
}
(( $+functions[_fslog__subcmd__help__subcmd__tail_commands] )) ||
_fslog__subcmd__help__subcmd__tail_commands() {
    local commands; commands=()
    _describe -t commands 'fslog help tail commands' commands "$@"
}
(( $+functions[_fslog__subcmd__list_commands] )) ||
_fslog__subcmd__list_commands() {
    local commands; commands=()
    _describe -t commands 'fslog list commands' commands "$@"
}
(( $+functions[_fslog__subcmd__monitor_commands] )) ||
_fslog__subcmd__monitor_commands() {
    local commands; commands=()
    _describe -t commands 'fslog monitor commands' commands "$@"
}
(( $+functions[_fslog__subcmd__read_commands] )) ||
_fslog__subcmd__read_commands() {
    local commands; commands=()
    _describe -t commands 'fslog read commands' commands "$@"
}
(( $+functions[_fslog__subcmd__search_commands] )) ||
_fslog__subcmd__search_commands() {
    local commands; commands=()
    _describe -t commands 'fslog search commands' commands "$@"
}
(( $+functions[_fslog__subcmd__tail_commands] )) ||
_fslog__subcmd__tail_commands() {
    local commands; commands=()
    _describe -t commands 'fslog tail commands' commands "$@"
}

if [ "$funcstack[1]" = "_fslog" ]; then
    _fslog "$@"
else
    compdef _fslog fslog
fi
