""" Configuration loading and parsing for the ER Model. """ from dataclasses import dataclass from pathlib import Path from typing import Dict, List, Tuple, Optional import yaml # Assuming these dataclasses are defined in er_model.er_model or a shared types module. # For now, let's duplicate them here or import them if they are easily accessible. # Ideally, they'd be in a place like 'er_model.types' # For this refactor, assuming they are in er_model.er_model and we'll import them. from er_model_core.types import Species, ProjectConfig, CarbonConfig def load_model_config( config_path: Optional[Path] = None, config_dict: Optional[Dict] = None ) -> Tuple[List[Species], ProjectConfig, CarbonConfig, str, bool, Dict]: """ Loads model configuration from a YAML file or a dictionary. Returns: A tuple containing: - List of Species objects - ProjectConfig object - CarbonConfig object - Growth model name (str) - Continuous growth flag (bool) - The raw config dictionary """ if config_dict is not None: cfg = config_dict elif config_path is not None: with open(config_path) as f: cfg = yaml.safe_load(f) else: raise ValueError("Either config_path or config_dict must be provided.") species_list = [Species(**s) for s in cfg["species"]] project_cfg = ProjectConfig(**cfg["project"]) carbon_cfg = CarbonConfig(**cfg["carbon"]) growth_model_name = cfg.get('growth_model', 'chapman_richards') continuous_growth_flag = cfg.get('continuous_growth', False) return species_list, project_cfg, carbon_cfg, growth_model_name, continuous_growth_flag, cfg