// Copyright (c) 2026 Alibaba Group and its affiliates

// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at

//     http://www.apache.org/licenses/LICENSE-2.0

// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package sdk

import "testing"

func TestRouteForModel(t *testing.T) {
	cases := []struct {
		name     string
		model    string
		wantTask string
	}{
		// Text generation
		{"qwen3-max", "qwen3-max", dashScopeTaskTextGeneration},
		{"qwen3-max suffix", "qwen3-max-001", dashScopeTaskTextGeneration},
		{"qwen3.7-max", "qwen3.7-max-2026", dashScopeTaskTextGeneration},
		{"qwen3.7 base falls back to text-generation", "qwen3.7-plus", dashScopeTaskTextGeneration},
		{"glm-5.1", "glm-5.1-chat", dashScopeTaskTextGeneration},
		{"glm-5.1 with deployment prefix", "pre-cmaas-test-glm-5.1-2", dashScopeTaskTextGeneration},
		{"deepseek-v3", "deepseek-v3", dashScopeTaskTextGeneration},
		{"deepseek-v3.2 wins over deepseek-v3", "deepseek-v3.2-instruct", dashScopeTaskTextGeneration},
		{"deepseek-v4-pro", "deepseek-v4-pro-001", dashScopeTaskTextGeneration},
		{"deepseek-v4-flash", "deepseek-v4-flash", dashScopeTaskTextGeneration},

		// Multimodal generation
		{"qwen3.5 base", "qwen3.5-plus", dashScopeTaskMultimodalGeneration},
		{"qwen3.5 with deployment prefix", "pre-cmaas-test-qwen3.5-397b-a17b-2", dashScopeTaskMultimodalGeneration},
		{"qwen3.6 base", "qwen3.6-plus-397b", dashScopeTaskMultimodalGeneration},
		{"kimi-k2.6", "kimi-k2.6-vl", dashScopeTaskMultimodalGeneration},
		{"MiniMax-M2.5 case-insensitive", "MiniMax-M2.5-Vision", dashScopeTaskMultimodalGeneration},

		// Unknown -> text-generation fallback
		{"unknown model", "some-future-model-xyz", dashScopeTaskTextGeneration},
		{"empty", "", dashScopeTaskTextGeneration},
	}

	for _, tc := range cases {
		t.Run(tc.name, func(t *testing.T) {
			got := routeForModel(tc.model)
			if got.task != tc.wantTask {
				t.Errorf("routeForModel(%q).task = %q, want %q", tc.model, got.task, tc.wantTask)
			}
			if got.taskGroup != dashScopeTaskGroupAIGC {
				t.Errorf("routeForModel(%q).taskGroup = %q, want %q", tc.model, got.taskGroup, dashScopeTaskGroupAIGC)
			}
			if got.function != dashScopeFunctionGeneration {
				t.Errorf("routeForModel(%q).function = %q, want %q", tc.model, got.function, dashScopeFunctionGeneration)
			}
		})
	}
}
