from pathlib import Path
from pprint import pprint

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,
- Descriptions of the required content for each section.

Restructure the original SRS to conform to the standard structure.
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}
```

## Descriptions of the required content for each section
```
{descriptions}
```

## Output
```markdown
"""


def construct_prompt(srs_orig: str, template: Template) -> Prompt:
    descriptions = "\n\n".join(
        "\n".join([section_template.title.to_str(), section_template.description])
        for section_template in template.section_templates
    )
    return Prompt(
        system=SYSTEM_MESSAGE,
        user=USER_MESSAGE.format(
            srs_orig=srs_orig,
            std_structure=template.overall_structure(),
            descriptions=descriptions,
        ),
    )


if __name__ == "__main__":
    template = load_template_yaml(Path("iso_template.yaml"))
    pprint(construct_prompt("{srs_orig}", template).model_dump_json(indent=4))
