import pytest
from src.models import Tool, ToolPreset, BiasProfile

def test_tool_model():
 tool = Tool(name="read_file", weight=5, parameter_bias={"path": "preferred"})
 data = tool.to_dict()
 assert data["name"] == "read_file"
 assert data["weight"] == 5
 assert data["parameter_bias"]["path"] == "preferred"
 
 tool2 = Tool.from_dict(data)
 assert tool2.name == "read_file"
 assert tool2.weight == 5
 assert tool2.parameter_bias["path"] == "preferred"

def test_tool_preset_extension():
 # Verify that ToolPreset correctly parses and serializes Tool objects
 tool_data = {"name": "read_file", "weight": 4, "parameter_bias": {"path": "high"}}
 raw_data = {"categories": {"General": [tool_data]}}
 
 # Test parsing via from_dict
 preset = ToolPreset.from_dict("test", raw_data)
 assert isinstance(preset.categories["General"][0], Tool)
 assert preset.categories["General"][0].weight == 4
 
 # Test serialization
 data = preset.to_dict()
 assert data["categories"]["General"][0]["weight"] == 4
 assert data["categories"]["General"][0]["name"] == "read_file"

def test_bias_profile_model():
 profile = BiasProfile(
  name="Execution-Focused",
  tool_weights={"run_powershell": 5},
  category_multipliers={"Surgical": 1.5}
 )
 data = profile.to_dict()
 assert data["tool_weights"]["run_powershell"] == 5
 assert data["category_multipliers"]["Surgical"] == 1.5
 
 # BiasProfile.from_dict expects 'name' inside the dict as well if coming from load_all_bias_profiles
 data["name"] = "Execution-Focused"
 profile2 = BiasProfile.from_dict(data)
 assert profile2.name == "Execution-Focused"
 assert profile2.tool_weights["run_powershell"] == 5
 assert profile2.category_multipliers["Surgical"] == 1.5
