package service

import (
	"testing"

	"github.com/orchard9/rdev/internal/domain"
)

func TestSDLCGenerateService_BuildPrompt(t *testing.T) {
	tests := []struct {
		name         string
		feature      string
		artifactType string
		taskID       string
		wantPrompt   string
	}{
		{
			name:         "spec artifact",
			feature:      "user-auth",
			artifactType: "spec",
			taskID:       "",
			wantPrompt:   "/spec-feature user-auth",
		},
		{
			name:         "design artifact",
			feature:      "user-auth",
			artifactType: "design",
			taskID:       "",
			wantPrompt:   "/design-feature user-auth",
		},
		{
			name:         "tasks artifact",
			feature:      "user-auth",
			artifactType: "tasks",
			taskID:       "",
			wantPrompt:   "/breakdown-feature user-auth",
		},
		{
			name:         "code with task_id",
			feature:      "user-auth",
			artifactType: "code",
			taskID:       "task-001",
			wantPrompt:   "/implement-task user-auth task-001",
		},
		{
			name:         "code without task_id",
			feature:      "user-auth",
			artifactType: "code",
			taskID:       "",
			wantPrompt:   "/implement-feature user-auth",
		},
		{
			name:         "qa artifact",
			feature:      "user-auth",
			artifactType: "qa",
			taskID:       "",
			wantPrompt:   "/run-qa user-auth",
		},
		{
			name:         "unknown artifact type falls back",
			feature:      "user-auth",
			artifactType: "unknown",
			taskID:       "",
			wantPrompt:   "Generate unknown artifact for feature user-auth",
		},
	}

	svc := &SDLCGenerateService{}

	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			got := svc.buildPrompt(tt.feature, tt.artifactType, tt.taskID)
			if got != tt.wantPrompt {
				t.Errorf("buildPrompt(%q, %q, %q) = %q, want %q",
					tt.feature, tt.artifactType, tt.taskID, got, tt.wantPrompt)
			}
		})
	}
}

func TestIsValidGenerateArtifactType(t *testing.T) {
	tests := []struct {
		artifactType string
		want         bool
	}{
		{"spec", true},
		{"design", true},
		{"tasks", true},
		{"code", true},
		{"qa", true},
		{"invalid", false},
		{"", false},
		{"review", false},
		{"audit", false},
	}

	for _, tt := range tests {
		t.Run(tt.artifactType, func(t *testing.T) {
			got := domain.IsValidGenerateArtifactType(tt.artifactType)
			if got != tt.want {
				t.Errorf("IsValidGenerateArtifactType(%q) = %v, want %v",
					tt.artifactType, got, tt.want)
			}
		})
	}
}
