import os
import sys
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..')))

import unittest
from unittest.mock import Mock, patch
from src.core import PrompTrace
# from src.model import Model
# from src.parser import Parser
# from src.tracer import TracerFactory

class TestPrompTrace(unittest.TestCase):
    def setUp(self):
        self.trace_type = "mock_type"
        self.trace_target = "mock_target"
        self.model_params = {
            "model": "gpt-3.5-turbo",
            "temperature": 0.7
        }
        self.prompt_trace = PrompTrace()

    @patch('src.core.Model')
    @patch('src.core.Parser')
    @patch('src.core.TracerFactory')
    @patch('src.core.EvaluationFactory')
    def test_run_method(self, mock_eval_factory, mock_tracer_factory, mock_parser, mock_model):
        # Setup test data
        test_experiments = {
                    "model" : {
                            "type": "deepseek",
                            "api_key": "sk-ea06e48b4f064229814b5526126037b2", 
                            "api_version": "", 
                            "endpoint": "https://api.deepseek.com",
                            "deployment": "deepseek-chat"
                    },
                    "prompt_template": "C:\work\mentisq\mentisq_api\promptrace\prompt_template\scorer\scorer_v2.prompt",
                    "dataset": "C:\work\mentisq\mentisq_api\promptrace\data\speaking_part2_v1.jsonl",
                    "evaluation": [
                            {'metric': 'is_numeric'}
                    ],
                    "tracer":{
                        "type": "file",
                        "target": "C:\work\mentisq\mentisq_api\promptrace\data\speaking_part2_v1.jsonl"
                    }           
          }

    #     # Setup mocks
    #     mock_experiment = Mock()
    #     mock_experiment.prompts = [Mock(), Mock()]
    #     mock_experiment.evaluations = [Mock()]
        
    #     mock_parser.parse.return_value = mock_experiment
        
    #     mock_evaluator = Mock()
    #     mock_eval_factory.get_evaluator.return_value = mock_evaluator
        
    #     mock_tracer = Mock()
    #     mock_tracer_factory.get_tracer.return_value = mock_tracer

        # Execute
        self.prompt_trace.run(test_experiments)

    #     # Assertions
    #     mock_parser.parse.assert_called_once()
    #     mock_model.assert_called_once_with(model_params=self.model_params)
    #     mock_model.return_value.invoke.assert_called_once_with(mock_experiment)
        
    #     # Verify evaluator was created and called for each prompt
    #     mock_eval_factory.get_evaluator.assert_called_once()
    #     self.assertEqual(mock_evaluator.evaluate.call_count, 2)
        
    #     # Verify tracer was created and called
    #     mock_tracer_factory.get_tracer.assert_called_once_with(
    #         self.trace_type, 
    #         self.trace_target
    #     )
    #     mock_tracer.trace.assert_called_once_with(mock_experiment, self.model_params)

if __name__ == '__main__':
    unittest.main() 