import os
import sys
import numpy as np
import math
import time

current_path = os.path.dirname(os.path.realpath(__file__))
sys.path.append(os.path.normpath(os.path.join(current_path, '../')))
sys.path.append(os.path.normpath(os.path.join(current_path, '../../')))
sys.path.append(os.path.normpath(os.path.join(current_path, '../../../')))

from lib.mgeo.class_defs import line_set
from open_scenario_importer_wrapper import OpenScenarioImporterWrapper
from open_scenario_client_wrapper import OpenScenarioClientWrapper

if __name__ == '__main__':
    # 실행할 시나리오 리스트
    scenario_list = [
        './data/openscenario/R_KR_PG_K-City/Scenario_CCRB_1.xosc',
        './data/openscenario/R_KR_PG_K-City/Scenario_CCRB_2.xosc',
        './data/openscenario/R_KR_PG_K-City/Scenario_CCRB_3.xosc',
        './data/openscenario/V_RHT_Suburb_03/Scenario_Animal_Deer.xosc',
        './data/openscenario/V_RHT_Suburb_03/Scenario_UTurn.xosc'
    ]

    client_wrapper = OpenScenarioClientWrapper('127.0.0.1', '7789')
    for scenario_file_path in scenario_list:
        # OpenSCENARIO 파일 Import
        importer_wrapper = OpenScenarioImporterWrapper(scenario_file_path)
        importer_wrapper.import_open_scenario()
        
        client_wrapper.set_open_scenario_importer(importer_wrapper.scenario_importer)
        
        # 시나리오 시작
        client_wrapper.start_scenario()

        # 시나리오가 종료될 때까지 대기
        # 시나리오가 종료되면 자동으로 OpenScenarioClientWrapper에서 Stop Scenario 호출
        while client_wrapper.is_stopped == False:
            time.sleep(1)
            pass


