using System.ComponentModel;
using Microsoft.Extensions.AI;
using ModelContextProtocol.Server;

namespace ColaFlow.Modules.Mcp.Application.SdkPrompts;

/// <summary>
/// MCP Prompts for project management tasks
/// Provides pre-defined prompt templates for AI interactions
/// </summary>
[McpServerPromptType]
public static class ProjectManagementPrompts
{
    [McpServerPrompt]
    [Description("Generate a Product Requirements Document (PRD) for an Epic")]
    public static ChatMessage GeneratePrdPrompt(
        [Description("The Epic title")] string epicTitle,
        [Description("Brief description of the Epic")] string epicDescription)
    {
        var promptText = $@"You are a Product Manager creating a Product Requirements Document (PRD).

**Epic**: {epicTitle}
**Description**: {epicDescription}

Please create a comprehensive PRD that includes:

1. **Executive Summary**
   - Brief overview of the feature
   - Business value and goals

2. **User Stories**
   - Who are the users?
   - What problems does this solve?

3. **Functional Requirements**
   - List all key features
   - User workflows and interactions

4. **Non-Functional Requirements**
   - Performance expectations
   - Security considerations
   - Scalability needs

5. **Acceptance Criteria**
   - Clear, testable criteria for completion
   - Success metrics

6. **Technical Considerations**
   - API requirements
   - Data models
   - Integration points

7. **Timeline and Milestones**
   - Estimated timeline
   - Key milestones
   - Dependencies

Please format the PRD in Markdown.";

        return new ChatMessage(ChatRole.User, promptText);
    }

    [McpServerPrompt]
    [Description("Break down an Epic into smaller Stories")]
    public static ChatMessage SplitEpicToStoriesPrompt(
        [Description("The Epic title")] string epicTitle,
        [Description("The Epic description or PRD")] string epicContent)
    {
        var promptText = $@"You are a Product Manager breaking down an Epic into manageable Stories.

**Epic**: {epicTitle}

**Epic Content**:
{epicContent}

Please break this Epic down into 5-10 User Stories following these guidelines:

1. **Each Story should**:
   - Be independently valuable
   - Be completable in 1-3 days
   - Follow the format: ""As a [user], I want [feature] so that [benefit]""
   - Include acceptance criteria

2. **Story Structure**:
   ```
   **Story Title**: [Concise title]
   **User Story**: As a [user], I want [feature] so that [benefit]
   **Description**: [Detailed description]
   **Acceptance Criteria**:
   - [ ] Criterion 1
   - [ ] Criterion 2
   - [ ] Criterion 3
   **Estimated Effort**: [Small/Medium/Large]
   **Priority**: [High/Medium/Low]
   ```

3. **Prioritize the Stories**:
   - Mark dependencies between stories
   - Suggest implementation order

Please output the Stories in Markdown format.";

        return new ChatMessage(ChatRole.User, promptText);
    }

    [McpServerPrompt]
    [Description("Generate acceptance criteria for a Story")]
    public static ChatMessage GenerateAcceptanceCriteriaPrompt(
        [Description("The Story title")] string storyTitle,
        [Description("The Story description")] string storyDescription)
    {
        var promptText = $@"You are a QA Engineer defining acceptance criteria for a User Story.

**Story**: {storyTitle}
**Description**: {storyDescription}

Please create comprehensive acceptance criteria following these guidelines:

1. **Criteria should be**:
   - Specific and measurable
   - Testable (can be verified)
   - Clear and unambiguous
   - Focused on outcomes, not implementation

2. **Include**:
   - Functional acceptance criteria (what the feature does)
   - Non-functional acceptance criteria (performance, security, UX)
   - Edge cases and error scenarios

3. **Format**:
   ```
   **Given**: [Initial context/state]
   **When**: [Action taken]
   **Then**: [Expected outcome]
   ```

Please output 5-10 acceptance criteria in Markdown format.";

        return new ChatMessage(ChatRole.User, promptText);
    }

    [McpServerPrompt]
    [Description("Analyze Sprint progress and provide insights")]
    public static ChatMessage AnalyzeSprintProgressPrompt(
        [Description("Sprint name")] string sprintName,
        [Description("Sprint data (JSON format)")] string sprintData)
    {
        var promptText = $@"You are a Scrum Master analyzing Sprint progress.

**Sprint**: {sprintName}

**Sprint Data**:
```json
{sprintData}
```

Please analyze the Sprint and provide:

1. **Progress Summary**:
   - Overall completion percentage
   - Story points completed vs. planned
   - Burndown trend analysis

2. **Risk Assessment**:
   - Tasks at risk of not completing
   - Blockers and bottlenecks
   - Velocity concerns

3. **Recommendations**:
   - Actions to get back on track
   - Tasks that could be descoped
   - Resource allocation suggestions

4. **Team Health**:
   - Workload distribution
   - Identify overloaded team members
   - Suggest load balancing

Please format the analysis in Markdown with clear sections.";

        return new ChatMessage(ChatRole.User, promptText);
    }

    [McpServerPrompt]
    [Description("Generate a Sprint retrospective summary")]
    public static ChatMessage GenerateRetrospectivePrompt(
        [Description("Sprint name")] string sprintName,
        [Description("Sprint completion data")] string sprintData,
        [Description("Team feedback (optional)")] string? teamFeedback = null)
    {
        var feedbackSection = string.IsNullOrEmpty(teamFeedback)
            ? ""
            : $@"

**Team Feedback**:
{teamFeedback}";

        var promptText = $@"You are a Scrum Master facilitating a Sprint Retrospective.

**Sprint**: {sprintName}

**Sprint Data**:
```json
{sprintData}
```
{feedbackSection}

Please create a comprehensive retrospective summary using the format:

1. **What Went Well** 🎉
   - Successes and achievements
   - Team highlights

2. **What Didn't Go Well** 😞
   - Challenges faced
   - Missed goals
   - Technical issues

3. **Lessons Learned** 📚
   - Key takeaways
   - Insights gained

4. **Action Items** 🎯
   - Specific, actionable improvements
   - Owner for each action
   - Target date

5. **Metrics** 📊
   - Velocity achieved
   - Story points completed
   - Sprint goal achievement

Please format the retrospective in Markdown.";

        return new ChatMessage(ChatRole.User, promptText);
    }
}
