from dlubal.api import rfem, common
import app.helpers.print_helper as print_helper

def main():
    # Connect to the RFEM application
    with rfem.Application() as rfem_app:
        # --- Design Configuration ---
        concrete_uls_config: rfem.concrete_design_objects.ConcreteDesignUlsConfiguration = rfem_app.get_object(
            obj=rfem.concrete_design_objects.ConcreteDesignUlsConfiguration(no=1)
        )
        # print_helper.header1(f"\concrete_uls_config:\n{concrete_uls_config}")

        # Create empty SettingsSurfaceEc2TreeTable and set only the values that we want to change
        settings_surface_ec2 = rfem.concrete_design_objects.ConcreteDesignUlsConfiguration.SettingsSurfaceEc2TreeTable()

        print_helper.header1_top(f'concrete_uls_config: no={concrete_uls_config.no} | {concrete_uls_config.name}')

        # Use empty SettingsSurfaceEc2TreeTable from new ULS Configuration
        chapter = 'surface_internal_forces'
        key1 = 'surface_internal_forces_no_optimization'
        design_path = [
            chapter,
            key1,
        ]
        design_value = False
        print(f"{design_path}: {design_value}")
        common.set_tree_value(
            tree=settings_surface_ec2,
            path=design_path,
            value=design_value
        )

        key1 = 'surface_internal_forces_optimization'
        design_path = [
            chapter,
            key1,
        ]
        design_value = True
        print(f"{design_path}: {design_value}")
        common.set_tree_value(
            tree=settings_surface_ec2,
            path=design_path,
            value=design_value
        )
        print_helper.header1_bottom()

        # Apply the updated configuration to the model
        rfem_app.update_object(
            obj=rfem.concrete_design_objects.ConcreteDesignUlsConfiguration(
                no=1,
                name='Slabs',
                assigned_to_surfaces=[4,5],
                settings_surface_ec2=settings_surface_ec2
            )
        )

if __name__ == '__main__':
    main()