package usecase

import (
	"fmt"
	"strings"
)

// QuestionGenerator creates questions from MC metadata when no
// pre-defined questions or doc_check_controls exist (Mode A fallback).
// For LLM-based generation (Mode B), see compiler_llm.go (Phase 7).

// GenerateFromMC derives 1-3 questions from a single MC.
func GenerateFromMC(mc MCInfo) []Question {
	name := mc.CanonicalName
	readable := strings.ReplaceAll(name, "_", " ")

	var questions []Question
	qBase := fmt.Sprintf("MC-%s", mc.MasterControlID)

	// Primary question: is the control implemented?
	questions = append(questions, Question{
		ID:           qBase + "-1",
		MCID:         mc.MasterControlID,
		MCName:       name,
		Text:         fmt.Sprintf("Ist '%s' in Ihrem Unternehmen implementiert?", readable),
		QuestionType: "yes_no",
		Severity:     inferMCSeverity(name),
		Regulation:   mc.RegSource,
		PassCriteria: []string{"Massnahme implementiert und aktiv"},
		FailCriteria: []string{"Nicht implementiert"},
	})

	// Secondary question: is there documentation?
	if mc.TotalControls >= 5 {
		questions = append(questions, Question{
			ID:           qBase + "-2",
			MCID:         mc.MasterControlID,
			MCName:       name,
			Text:         fmt.Sprintf("Ist '%s' dokumentiert und nachweisbar?", readable),
			QuestionType: "yes_no",
			EvidenceRequired: true,
			Severity:     "MEDIUM",
			Regulation:   mc.RegSource,
			PassCriteria: []string{"Dokumentation vorhanden und aktuell"},
			FailCriteria: []string{"Keine oder veraltete Dokumentation"},
			DependsOn:    qBase + "-1",
		})
	}

	// Tertiary question for large MCs: review cycle
	if mc.TotalControls >= 15 {
		questions = append(questions, Question{
			ID:           qBase + "-3",
			MCID:         mc.MasterControlID,
			MCName:       name,
			Text:         fmt.Sprintf("Wird '%s' regelmaessig ueberprueft und aktualisiert?", readable),
			QuestionType: "yes_no",
			Severity:     "LOW",
			Regulation:   mc.RegSource,
			PassCriteria: []string{"Regelmaessiger Review-Zyklus definiert"},
			FailCriteria: []string{"Kein Review-Prozess"},
			DependsOn:    qBase + "-1",
		})
	}

	return questions
}
