package handlers

import "cursor-api-proxy/internal/config"

func ResolveModel(requested string, lastModelRef *string, cfg config.BridgeConfig) string {
	isAuto := requested == "auto"
	var explicitModel string
	if requested != "" && !isAuto {
		explicitModel = requested
	}
	if explicitModel != "" {
		*lastModelRef = explicitModel
	}
	if isAuto {
		return "auto"
	}
	if explicitModel != "" {
		return explicitModel
	}
	if cfg.StrictModel && *lastModelRef != "" {
		return *lastModelRef
	}
	if *lastModelRef != "" {
		return *lastModelRef
	}
	return cfg.DefaultModel
}
