// Copyright 2026 International Digital Economy Academy
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

///|
/// Where a value/flag came from.
#warnings("-deprecated_syntax")
pub enum ValueSource {
  Argv
  Env
  Default
} derive(Eq, Show, @debug.Debug)

///|
/// Parse results for declarative commands.
///
/// - `flags` stores final boolean states for flag args.
/// - `values` stores collected option/positional values.
/// - `flag_counts` stores occurrence counts for `FlagAction::Count`.
/// - `sources` records the final source (`Argv` / `Env` / `Default`) per arg.
/// - `subcommand` stores nested matches for the selected subcommand.
pub struct Matches {
  flags : Map[String, Bool]
  values : Map[String, Array[String]]
  flag_counts : Map[String, Int]
  sources : Map[String, ValueSource]
  subcommand : (String, Matches)?
  priv counts : Map[String, Int]
  priv flag_sources : Map[String, ValueSource]
  priv value_sources : Map[String, ValueSource]
  priv mut parsed_subcommand : (String, Matches)?
} derive(@debug.Debug)

///|
fn new_matches_parse_state() -> Matches {
  {
    flags: Map([]),
    values: Map([]),
    flag_counts: Map([]),
    sources: Map([]),
    subcommand: None,
    counts: Map([]),
    flag_sources: Map([]),
    value_sources: Map([]),
    parsed_subcommand: None,
  }
}