use crate::e2e::codegen::call_ir::{CallIr, resolve_declared_result_type};
use crate::e2e::config::{CallConfig, E2eConfig};
use crate::e2e::field_access::{DartFirstClassMap, FieldResolver};
use crate::e2e::fixture::Fixture;
use std::collections::{HashMap, HashSet};
#[allow(clippy::too_many_arguments)]
pub(super) fn build_call_field_resolver(
e2e_config: &E2eConfig,
call_config: &CallConfig,
fixture: &Fixture,
lang: &str,
dart_first_class_map: &DartFirstClassMap,
type_defs: &[crate::core::ir::TypeDef],
enums: &[crate::core::ir::EnumDef],
functions: &[crate::core::ir::FunctionDef],
) -> FieldResolver {
let mut effective_enum_fields: HashSet<String> = e2e_config.effective_fields_enum(call_config).clone();
if let Some(overrides) = call_config.overrides.get(lang) {
effective_enum_fields.extend(overrides.enum_fields.keys().cloned());
}
let call_root_type = resolve_declared_result_type(call_config, lang, CallIr { functions, type_defs });
let (ir_reachable_fields, ir_known_excluded_fields, ir_optional_fields) = FieldResolver::ir_field_sets(type_defs);
FieldResolver::new_with_dart_first_class(
e2e_config.effective_fields(call_config),
e2e_config.effective_fields_optional(call_config),
e2e_config.effective_result_fields(call_config),
e2e_config.effective_fields_array(call_config),
e2e_config.effective_fields_method_calls(call_config),
&HashMap::new(),
dart_first_class_map.clone(),
)
.with_display_as_text_fields(e2e_config.effective_fields_display_as_text(call_config).clone())
.with_dart_root_type(super::dart_call_result_type(call_config).or_else(|| dart_first_class_map.root_type.clone()))
.with_enum_fields(effective_enum_fields)
.with_ir_enum_map(FieldResolver::ir_enum_fields(type_defs, enums), call_root_type.clone())
.with_ir_collection_map(FieldResolver::ir_collection_fields(type_defs), call_root_type)
.with_ir_fields(ir_reachable_fields, ir_known_excluded_fields, ir_optional_fields)
.with_anchored_optional_paths(fixture.assertions.iter().filter_map(|a| a.field.as_deref()))
}