from enum import StrEnum
from pathlib import Path
from typing import Annotated

from pydantic import BaseModel, Field
from unique_toolkit._common.docx_generator import DocxGeneratorConfig
from unique_toolkit._common.pydantic.rjsf_tags import RJSFMetaTag
from unique_toolkit._common.pydantic_helpers import get_configuration_dict

from unique_swot.utils import load_template

# Get the directory containing this file
_PROMPTS_DIR = Path(__file__).parent


REPORT_BODY_TEMPLATE: str = load_template(_PROMPTS_DIR, "report_body_template.j2")
REPORT_STRUCTURE_TEMPLATE: str = load_template(
    _PROMPTS_DIR, "report_structure_template.j2"
)


class RendererType(StrEnum):
    DOCX = "docx"
    CHAT = "chat"


class ReportRendererConfig(BaseModel):
    model_config = get_configuration_dict()

    report_structure_template: Annotated[
        str,
        RJSFMetaTag.StringWidget.textarea(
            rows=len(REPORT_STRUCTURE_TEMPLATE.split("\n"))
        ),
    ] = Field(
        default=REPORT_STRUCTURE_TEMPLATE,
        description="Jinja2 template for the report structure.",
    )

    report_body_template: Annotated[
        str,
        RJSFMetaTag.StringWidget.textarea(rows=len(REPORT_BODY_TEMPLATE.split("\n"))),
    ] = Field(
        default=REPORT_BODY_TEMPLATE,
        description="Jinja2 template for the report.",
    )

    renderer_type: RendererType = Field(
        default=RendererType.DOCX,
        description="The type of renderer to use.",
    )

    docx_renderer_config: DocxGeneratorConfig = Field(
        default_factory=DocxGeneratorConfig,
        description="The configuration for the DOCX renderer.",
    )
    ingest_docx_report: bool = Field(
        default=False,
        description="Ingesting the DOCX report into the chat allows the user to ask follow-up questions. It also allows side view when clicking on the reference.",
    )
