package llm

import (
	"testing"
)

func TestConfigValidate(t *testing.T) {
	tests := []struct {
		name    string
		cfg     Config
		wantErr bool
	}{
		{
			name:    "empty config",
			cfg:     Config{},
			wantErr: true,
		},
		{
			name: "missing model",
			cfg: Config{
				URL: "https://api.example.com",
			},
			wantErr: true,
		},
		{
			name: "missing URL",
			cfg: Config{
				Model: "gpt-4o",
			},
			wantErr: true,
		},
		{
			name: "invalid timeout",
			cfg: Config{
				Model:   "gpt-4o",
				URL:     "https://api.example.com",
				Timeout: "not-a-duration",
			},
			wantErr: true,
		},
		{
			name: "valid minimal config",
			cfg: Config{
				Model: "gpt-4o",
				URL:   "https://api.example.com",
			},
			wantErr: false,
		},
		{
			name: "valid config with timeout",
			cfg: Config{
				Model:   "gpt-4o",
				URL:     "https://api.example.com",
				Timeout: "15m",
			},
			wantErr: false,
		},
		{
			name: "valid config with complex timeout",
			cfg: Config{
				Model:   "gpt-4o",
				URL:     "https://api.example.com",
				Timeout: "1h30m45s",
			},
			wantErr: false,
		},
		{
			name: "valid full config",
			cfg: Config{
				Key:          "sk-test-key",
				Model:        "gpt-4o",
				SystemPrompt: "You are a helpful assistant.",
				Timeout:      "30m",
				URL:          "https://api.example.com",
			},
			wantErr: false,
		},
	}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			err := tt.cfg.Validate()
			if (err != nil) != tt.wantErr {
				t.Errorf(
					"Validate() error = %v, wantErr %v",
					err, tt.wantErr,
				)
			}
		})
	}
}
