File size: 3,537 Bytes
c9a6a77
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"""
JSON validation utilities for Product Vision Board data.
"""
import json
from typing import Tuple, Dict, Optional


class PVBValidator:
    """Validates and parses Product Vision Board JSON data."""

    # Expected sections in a Product Vision Board
    EXPECTED_SECTIONS = [
        "1. Utilisateur Cible",
        "2. Description du Produit",
        "3. Fonctionnalités Clés",
        "4. Enjeux et Indicateurs"
    ]

    @staticmethod
    def validate_pvb_json(user_input: str) -> Tuple[bool, Optional[Dict], Optional[str]]:
        """
        Validate if the user input is valid Product Vision Board JSON.

        Args:
            user_input: String that might be JSON

        Returns:
            Tuple of (is_valid, parsed_data, error_message)
        """
        # Try to parse as JSON
        try:
            data = json.loads(user_input)
        except json.JSONDecodeError as e:
            return False, None, f"Invalid JSON format: {str(e)}"

        # Check if it's a dictionary
        if not isinstance(data, dict):
            return False, None, "JSON must be an object/dictionary, not an array or primitive"

        # Check for at least some expected sections
        found_sections = [section for section in PVBValidator.EXPECTED_SECTIONS if section in data]

        if len(found_sections) == 0:
            # Not a PVB, might be a regular JSON
            return False, None, "No Product Vision Board sections found"

        # Validate that sections contain lists
        for section in found_sections:
            if not isinstance(data[section], list):
                return False, None, f"Section '{section}' must be a list"

        # Valid PVB JSON
        return True, data, None

    @staticmethod
    def is_pvb_like(user_input: str) -> bool:
        """
        Quick check if input looks like PVB JSON (without full validation).

        Args:
            user_input: User input string

        Returns:
            True if it looks like PVB JSON
        """
        # Check if it starts with { and contains at least one expected section
        if not user_input.strip().startswith("{"):
            return False

        for section in PVBValidator.EXPECTED_SECTIONS:
            if section in user_input:
                return True

        return False

    @staticmethod
    def extract_summary(pvb_data: Dict) -> str:
        """
        Extract or generate a summary from PVB data.

        Args:
            pvb_data: Parsed PVB dictionary

        Returns:
            Summary string
        """
        if "Summary" in pvb_data:
            return pvb_data["Summary"]

        # Generate basic summary from sections
        summary_parts = []
        if "1. Utilisateur Cible" in pvb_data:
            users = pvb_data["1. Utilisateur Cible"]
            summary_parts.append(f"Target users: {', '.join(users)}")

        if "4. Enjeux et Indicateurs" in pvb_data:
            objectives = pvb_data["4. Enjeux et Indicateurs"]
            if objectives:
                summary_parts.append(f"Key objective: {objectives[0]}")

        return " | ".join(summary_parts) if summary_parts else "Product Vision Board"


# Convenience functions
def validate_pvb_json(user_input: str) -> Tuple[bool, Optional[Dict], Optional[str]]:
    """Shorthand for PVBValidator.validate_pvb_json()"""
    return PVBValidator.validate_pvb_json(user_input)


def is_pvb_like(user_input: str) -> bool:
    """Shorthand for PVBValidator.is_pvb_like()"""
    return PVBValidator.is_pvb_like(user_input)