package runtime

// ModelReplacement defines a per-key model replacement rule tracked by the APR dispatcher.
type ModelReplacement struct {
	ID           string  `yaml:"-" json:"id"`
	APIKey       string  `yaml:"api_key" json:"api_key"`
	Model        string  `yaml:"model" json:"model"`
	TargetModel  string  `yaml:"target_model" json:"target_model"`
	Probability  float64 `yaml:"probability" json:"probability"`
	RequestCount uint64  `yaml:"-" json:"request_count"`
	HitCount     uint64  `yaml:"-" json:"hit_count"`
}

// ModelRoute defines model routing for one vendor.
type ModelRoute struct {
	ID        string       `yaml:"id,omitempty" json:"id"`
	Vendor    string       `yaml:"vendor" json:"vendor"`
	Models    []string     `yaml:"models,omitempty" json:"models,omitempty"`
	Providers []string     `yaml:"providers,omitempty" json:"providers,omitempty"`
	Groups    []RouteGroup `yaml:"groups,omitempty" json:"groups,omitempty"`
}

// RouteGroup defines one model/provider subgroup inside a route.
type RouteGroup struct {
	ID        string   `yaml:"id,omitempty" json:"id"`
	Models    []string `yaml:"models" json:"models"`
	Providers []string `yaml:"providers" json:"providers"`
}

// EffectiveGroups returns explicit groups when present, otherwise wraps flat models/providers.
func (route *ModelRoute) EffectiveGroups() []RouteGroup {
	if route == nil {
		return nil
	}
	if len(route.Groups) > 0 {
		return route.Groups
	}
	return []RouteGroup{{
		Models:    append([]string(nil), route.Models...),
		Providers: append([]string(nil), route.Providers...),
	}}
}
