import unittest
from datetime import datetime
from dotenv import load_dotenv
from time import sleep
from msfabricpysdkcore.coreapi import FabricClientCore

load_dotenv()

class TestFabricClientCore(unittest.TestCase):

    def __init__(self, *args, **kwargs):
        super(TestFabricClientCore, self).__init__(*args, **kwargs)
        #load_dotenv()
        self.fc = FabricClientCore()

    def test_eventstreams(self):

            fc = self.fc
            workspace_id = 'd8a5abe0-9eed-406d-ab46-343bc57ddbe5'

            datetime_str = datetime.now().strftime("%Y%m%d%H%M%S")
            es_name = "es" + datetime_str

            eventstream = fc.create_eventstream(workspace_id, display_name=es_name)
            self.assertEqual(eventstream.display_name, es_name)

            eventstreams = fc.list_eventstreams(workspace_id)
            eventstream_names = [es.display_name for es in eventstreams]
            self.assertGreater(len(eventstreams), 0)
            self.assertIn(es_name, eventstream_names)

            
            es = fc.get_eventstream(workspace_id, eventstream_name=es_name)
            self.assertIsNotNone(es.id)
            self.assertEqual(es.display_name, es_name)

            es2 = fc.update_eventstream(workspace_id, es.id, display_name=f"{es_name}2")

            es = fc.get_eventstream(workspace_id, eventstream_id=es.id)
            self.assertEqual(es.display_name, f"{es_name}2")
            self.assertEqual(es.id, es2.id)

            status_code = fc.delete_eventstream(workspace_id, es.id)
            self.assertEqual(status_code, 200)