from typing import Dict, List import yaml def load_catalog(path="configs/parts_catalog.yaml"): with open(path,"r",encoding="utf-8") as f: return yaml.safe_load(f) def load_regions(path="configs/regions.yaml"): with open(path,"r",encoding="utf-8") as f: return yaml.safe_load(f) def price_issues(issues: List[str], region_code: str="IN-HYD", catalog=None, regions=None) -> Dict: catalog = catalog or load_catalog() regions = regions or load_regions() parts = catalog.get("issues", {}) tax_rate = float(catalog.get("tax_rate", 0.18)) region = regions["regions"][region_code] currency = region["currency"] labor_rate = float(region["labor_rate_per_hour"]) p_mult = float(region["parts_multiplier"]) items = [] subtotal = 0.0 for label in issues: if label == "diagnostic_inspection": items.append({ "issue": label, "solution": "Perform comprehensive inspection to localize faults.", "labor_hours": 0.5, "labor_cost": round(0.5*labor_rate,2), "parts": [], "parts_cost": 0.0, "line_total": round(0.5*labor_rate,2), "currency": currency }) subtotal += 0.5*labor_rate continue spec = parts.get(label, {"parts": [], "labor_hours": 1.0}) hours = float(spec.get("labor_hours",1.0)) parts_cost = sum([float(p.get("cost",0.0))*p_mult for p in spec.get("parts",[])]) labor_cost = hours * labor_rate line = labor_cost + parts_cost solution = DEFAULT_SOLUTIONS.get(label, "Repair as per standard service procedure.") items.append({ "issue": label, "solution": solution, "labor_hours": hours, "labor_cost": round(labor_cost,2), "parts": spec.get("parts",[]), "parts_cost": round(parts_cost,2), "line_total": round(line,2), "currency": currency }) subtotal += line tax = round(tax_rate * subtotal,2) grand = round(subtotal + tax,2) return {"region": region_code, "currency": currency, "items": items, "subtotal": round(subtotal,2), "tax": tax, "grand_total": grand} DEFAULT_SOLUTIONS = { "scratch_dent": "Panel dent repair and surface leveling; finish with primer and paint blend.", "paint_damage": "Prep, prime, color-match repaint, and clear coat application.", "cracked_windshield": "Replace windshield and seal; calibrate sensors if equipped.", "flat_tire": "Replace tire; balance and perform wheel alignment check.", "engine_leak": "Identify leak source; replace gaskets/seals; top up fluids and clean bay.", "brake_wear": "Replace brake pads; inspect rotors and bleed lines if required.", "headlight_fault": "Replace bulb/assembly; verify wiring and aim beam.", "battery_corrosion": "Clean terminals; replace corroded connectors; apply protective grease.", "rust": "Sand, treat with rust converter; prime and protect underbody.", "bumper_damage": "Replace or plastic-weld bumper; refit and paint as needed.", "diagnostic_inspection": "Full diagnostic scan and physical inspection to isolate faults." }