from typing import Type, List

from pydantic import BaseModel, Field
from sqlalchemy.orm import Session

from app.core.tools.base_tool import BaseTool
from app.models.run import Run
from app.services.file.file import FileService


class FileContnetToolInput(BaseModel):
    """This tool requires no arguments."""
    pass


class FileContnetTool(BaseTool):
    name: str = "read_full_file_content"
    description: str = (
        "ONLY trigger this tool when the user explicitly requests to read the COMPLETE or FULL content of an uploaded file. "
        "Key trigger phrases include: '读取全部内容', '显示所有内容', '完整的文件', 'read the full content', 'read all content', 'complete file', 'entire content'. "
        "Critical rules: "
        "1. STRICTLY requires an explicit user command to read everything. Do NOT trigger for summaries, searches, or overviews. "
        "2. This tool is mutually exclusive with 'file_search' or 'file_content_processor'. If this tool is triggered, those must NOT be used. "
        "3. Operates as a strict singleton: ABSOLUTELY ONLY 1 invocation is permitted per user request. "
        "4. MUST confirm that files are available before execution."
    )
    args_schema: Type[BaseModel] = FileContnetToolInput

    def __init__(self) -> None:
        super().__init__()
        self.file_ids = []

    def configure(self, session: Session, run: Run, **kwargs):
        if run.file_ids is not None and len(run.file_ids) > 0:
            self.file_ids = run.file_ids

    def run(self) -> dict:
        files = []
        if self.file_ids is not None and len(self.file_ids) > 0:
            files = FileService.list_chunks(ids=self.file_ids)
        return files

    def instruction_supplement(self) -> str:
        """
        为 Retrieval 提供文件选择信息，用于 llm 调用抉择
        """
        return ""
