package server

// RoleProfile provides persona metadata for a council role so CHORUS agents can
// load the correct prompt stack after claiming a role.
type RoleProfile struct {
	RoleName          string   `json:"role_name"`
	DisplayName       string   `json:"display_name"`
	PromptKey         string   `json:"prompt_key"`
	PromptPack        string   `json:"prompt_pack"`
	Capabilities      []string `json:"capabilities,omitempty"`
	BriefRoutingHint  string   `json:"brief_routing_hint,omitempty"`
	DefaultBriefOwner bool     `json:"default_brief_owner,omitempty"`
}

func defaultRoleProfiles() map[string]RoleProfile {
	const promptPack = "chorus/prompts/human-roles.yaml"

	profiles := map[string]RoleProfile{
		"systems-analyst": {
			RoleName:         "systems-analyst",
			DisplayName:      "Systems Analyst",
			PromptKey:        "systems-analyst",
			PromptPack:       promptPack,
			Capabilities:     []string{"requirements-analysis", "ucxl-navigation", "context-curation"},
			BriefRoutingHint: "requirements",
		},
		"senior-software-architect": {
			RoleName:         "senior-software-architect",
			DisplayName:      "Senior Software Architect",
			PromptKey:        "senior-software-architect",
			PromptPack:       promptPack,
			Capabilities:     []string{"architecture", "trade-study", "diagramming"},
			BriefRoutingHint: "architecture",
		},
		"tpm": {
			RoleName:          "tpm",
			DisplayName:       "Technical Program Manager",
			PromptKey:         "tpm",
			PromptPack:        promptPack,
			Capabilities:      []string{"program-coordination", "risk-tracking", "stakeholder-comm"},
			BriefRoutingHint:  "coordination",
			DefaultBriefOwner: true,
		},
		"security-architect": {
			RoleName:         "security-architect",
			DisplayName:      "Security Architect",
			PromptKey:        "security-architect",
			PromptPack:       promptPack,
			Capabilities:     []string{"threat-modeling", "compliance", "secure-design"},
			BriefRoutingHint: "security",
		},
		"devex-platform-engineer": {
			RoleName:         "devex-platform-engineer",
			DisplayName:      "DevEx Platform Engineer",
			PromptKey:        "devex-platform-engineer",
			PromptPack:       promptPack,
			Capabilities:     []string{"tooling", "developer-experience", "automation"},
			BriefRoutingHint: "platform",
		},
		"qa-test-engineer": {
			RoleName:         "qa-test-engineer",
			DisplayName:      "QA Test Engineer",
			PromptKey:        "qa-test-engineer",
			PromptPack:       promptPack,
			Capabilities:     []string{"test-strategy", "automation", "validation"},
			BriefRoutingHint: "quality",
		},
		"sre-observability-lead": {
			RoleName:         "sre-observability-lead",
			DisplayName:      "SRE Observability Lead",
			PromptKey:        "sre-observability-lead",
			PromptPack:       promptPack,
			Capabilities:     []string{"observability", "resilience", "slo-management"},
			BriefRoutingHint: "reliability",
		},
		"technical-writer": {
			RoleName:         "technical-writer",
			DisplayName:      "Technical Writer",
			PromptKey:        "technical-writer",
			PromptPack:       promptPack,
			Capabilities:     []string{"documentation", "knowledge-capture", "ucxl-indexing"},
			BriefRoutingHint: "documentation",
		},
	}

	return profiles
}

func (s *Server) lookupRoleProfile(roleName, displayName string) RoleProfile {
	if profile, ok := s.roleProfiles[roleName]; ok {
		if displayName != "" {
			profile.DisplayName = displayName
		}
		return profile
	}

	return RoleProfile{
		RoleName:    roleName,
		DisplayName: displayName,
		PromptKey:   roleName,
		PromptPack:  "chorus/prompts/human-roles.yaml",
	}
}
