from pathlib import Path
from pprint import pprint
from typing import List

from srs2std.llms import Prompt
from srs2std.srs.template import Template, load_template_yaml

SYSTEM_MESSAGE = """\
## Persona
You are an experienced requirements engineer.

## Instructions
You will be provided with:
- The original software requirements specification (SRS),
- The standard SRS section structure,
- The section to be generated,
- The description of the required content for the section.

Restructure the original SRS to conform to the standard structure.
Output only the specified section.
Retain necessary and sufficient information from the original SRS.
Output "[N/A]" for any required content missing from the original SRS.

## Output format
Output strictly in Markdown (CommonMark) format.
Use only headers, paragraphs, and lists.
Do NOT use any tables, code blocks, HTML, or extension syntax (e.g., Mermaid).\
"""


USER_MESSAGE = """\
## The original SRS
```
{srs_orig}
```

## The standard SRS section structure
```
{std_structure}
```

## The section to be generated
```
{section_tobe_generated}
```

## The description of the required content for the section
```
{description}
```

## Output
```markdown
{section_tobe_generated}
"""


def construct_prompts(srs_orig: str, template: Template) -> List[Prompt]:
    prompts = [
        Prompt(
            system=SYSTEM_MESSAGE,
            user=USER_MESSAGE.format(
                srs_orig=srs_orig,
                std_structure=template.overall_structure(),
                section_tobe_generated=section_template.title.to_str(),
                description=section_template.description,
            ),
        )
        for section_template in template.section_templates
        if section_template.description
    ]
    return prompts


if __name__ == "__main__":
    template = load_template_yaml(Path("iso_template.yaml"))
    pprint(
        [
            prompt.model_dump_json(indent=4)
            for prompt in construct_prompts("{srs_orig}", template)
        ]
    )
