# Copyright (c) 2025 Patrick Motsch
# All rights reserved.
import logging
from typing import List
from .aicoreBase import BaseConnectorAi
from modules.datamodels.datamodelAi import AiModel, PriorityEnum, ProcessingModeEnum, OperationTypeEnum, AiModelCall, AiModelResponse, createOperationTypeRatings

# Configure logger
logger = logging.getLogger(__name__)

class AiInternal(BaseConnectorAi):
    """Internal connector for document processing, generation, and rendering."""
    
    def __init__(self):
        super().__init__()
        logger.info("Internal Connector initialized")
    
    def getConnectorType(self) -> str:
        """Get the connector type identifier."""
        return "internal"
    
    def getModels(self) -> List[AiModel]:
        """Get all available internal models."""
        return [
            AiModel(
                name="internal-extractor",
                displayName="Internal Document Extractor",
                connectorType="internal",
                apiUrl="internal://extract",
                temperature=0.0,  # Not applicable for extraction
                maxTokens=0,  # Not token-based
                contextLength=0,
                costPer1kTokensInput=0.0,
                costPer1kTokensOutput=0.0,
                speedRating=9,  # Very fast for internal operations
                qualityRating=8,  # Good quality
                # capabilities removed (not used in business logic)
                functionCall=self.extractDocument,
                priority=PriorityEnum.COST,
                processingMode=ProcessingModeEnum.BASIC,
                operationTypes=createOperationTypeRatings(),
                version="internal-extractor-v1",
                calculatepriceCHF=lambda processingTime, bytesSent, bytesReceived: 0.001 + (bytesSent + bytesReceived) / (1024 * 1024) * 0.01
            ),
            AiModel(
                name="internal-generator",
                displayName="Internal Document Generator",
                connectorType="internal",
                apiUrl="internal://generate",
                temperature=0.0,  # Not applicable for generation
                maxTokens=0,  # Not token-based
                contextLength=0,
                costPer1kTokensInput=0.0,
                costPer1kTokensOutput=0.0,
                speedRating=8,  # Fast for generation
                qualityRating=8,  # Good quality
                # capabilities removed (not used in business logic)
                functionCall=self.generateDocument,
                priority=PriorityEnum.COST,
                processingMode=ProcessingModeEnum.BASIC,
                operationTypes=createOperationTypeRatings(),
                version="internal-generator-v1",
                calculatepriceCHF=lambda processingTime, bytesSent, bytesReceived: 0.002 + (bytesReceived / (1024 * 1024)) * 0.005
            ),
            AiModel(
                name="internal-renderer",
                displayName="Internal Document Renderer",
                connectorType="internal",
                apiUrl="internal://render",
                temperature=0.0,  # Not applicable for rendering
                maxTokens=0,  # Not token-based
                contextLength=0,
                costPer1kTokensInput=0.0,
                costPer1kTokensOutput=0.0,
                speedRating=7,  # Good for rendering
                qualityRating=9,  # High quality rendering
                # capabilities removed (not used in business logic)
                functionCall=self.renderDocument,
                priority=PriorityEnum.QUALITY,
                processingMode=ProcessingModeEnum.DETAILED,
                operationTypes=createOperationTypeRatings(),
                version="internal-renderer-v1",
                calculatepriceCHF=lambda processingTime, bytesSent, bytesReceived: 0.003 + (bytesReceived / (1024 * 1024)) * 0.008
            )
        ]
    
    async def extractDocument(self, modelCall: AiModelCall) -> AiModelResponse:
        """
        NOP - we only need the model for price calculations
        """
        logger.error(f"Document extraction not to call here")
        return AiModelResponse(
            content="",
            success=False,
            error="Internal connector should not be called directly"
        )
    
    async def generateDocument(self, modelCall: AiModelCall) -> AiModelResponse:
        """
        NOP - we only need the model for price calculations
        """
        logger.error(f"Document generation not to call here")
        return AiModelResponse(
            content="",
            success=False,
            error="Internal connector should not be called directly"
        )
    
    async def renderDocument(self, modelCall: AiModelCall) -> AiModelResponse:
        """
        NOP - we only need the model for price calculations
        """
        logger.error(f"Document rendering not to call here")
        return AiModelResponse(
            content="",
            success=False,
            error="Internal connector should not be called directly"
        )
    
