import sys
import os
import json
import unittest

# Add src to path for import
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '../src')))

from farmdirect_core.ai_engine import engine

class TestFarmDirectAI(unittest.TestCase):

    def test_predict_demand(self):
        input_data = json.dumps({
            "product_name": "Tomato",
            "price": 30,
            "season": "winter"
        })
        result = engine.predict_demand(input_data)
        data = json.loads(result)
        self.assertEqual(data['status'], 'success')
        self.assertIn('predicted_demand_score', data)
        print(f"Prediction: {data}")

    def test_pricing(self):
        result = engine.recommend_pricing("Potato", 20.0, 25.0)
        data = json.loads(result)
        self.assertEqual(data['status'], 'success')
        self.assertTrue(data['recommended_price'] > 20.0)
        print(f"Pricing: {data}")

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