package batch

import "sub2api-cn-relay-manager/internal/probe"

type ImportRoutingStrategy struct {
	UseRawChatCompletions bool
	SkipResponsesChecks   bool
	RetryInitial503       bool
	TreatProbe403Advisory bool
}

func BuildImportRoutingStrategy(profile *probe.CapabilityProfile) ImportRoutingStrategy {
	strategy := ImportRoutingStrategy{
		RetryInitial503: true,
	}
	if profile == nil {
		return strategy
	}

	if profile.TransportProfile.SupportsOpenAIChatCompletions && !profile.TransportProfile.SupportsOpenAIResponses {
		strategy.UseRawChatCompletions = true
		strategy.SkipResponsesChecks = true
	}
	for _, advisory := range profile.TransportProfile.KnownAdvisories {
		switch advisory {
		case "responses_unsupported_but_chat_ok":
			strategy.UseRawChatCompletions = true
			strategy.SkipResponsesChecks = true
		case "initial_probe_race_expected":
			strategy.TreatProbe403Advisory = true
		}
	}
	return strategy
}
