CLASS zcl_flifm_router DEFINITION
  PUBLIC
  CREATE PUBLIC .

  PUBLIC SECTION.

    INTERFACES zif_flifm_router .

    ALIASES on_routing
      FOR zif_flifm_router~on_routing .
  PROTECTED SECTION.
  PRIVATE SECTION.

    METHODS _routes
      IMPORTING
        !is_route_data TYPE zif_flifm_definitions=>tys_route_data
      RAISING
        zcx_flifm_exception .
    METHODS _filab_service
      IMPORTING
        !is_route_data TYPE zif_flifm_definitions=>tys_route_data
      RAISING
        zcx_flifm_exception .
ENDCLASS.



CLASS ZCL_FLIFM_ROUTER IMPLEMENTATION.


  METHOD zif_flifm_router~on_routing.

    DATA: ls_route_data TYPE zif_flifm_definitions=>tys_route_data.

    ls_route_data-route   = iv_route.
    ls_route_data-menu    = iv_menu.
    ls_route_data-company = iv_company.
    ls_route_data-action  = iv_action.
    ls_route_data-parent  = io_parent.

    CASE ls_route_data-route.
      WHEN zif_flifm_definitions=>c_routes-filab_services.

        _filab_service(
          EXPORTING
            is_route_data = ls_route_data ).

      WHEN OTHERS.

        SELECT COUNT(*) UP TO 1 ROWS
          FROM zflifmt_routes
          WHERE route = ls_route_data-route.

        IF sy-subrc = 0.
          _routes(
            EXPORTING
              is_route_data = ls_route_data ).
        ELSE.
          zcx_flifm_exception=>raise_t100( iv_msgno = 016 iv_msgv1 = |'{ ls_route_data-route }'| ).
        ENDIF.
    ENDCASE.

  ENDMETHOD.


  METHOD _filab_service.

    CASE is_route_data-action.
      WHEN zif_flifm_definitions=>c_action-go_filab.
        zcl_flifm_services_filab=>open_filab_homepage( ).
      WHEN zif_flifm_definitions=>c_action-go_help.
        zcl_flifm_services_filab=>open_filab_help( ).
      WHEN OTHERS.
        zcx_flifm_exception=>raise_t100( iv_msgno = 004 iv_msgv1 = |{ is_route_data-action }| ).
    ENDCASE.

  ENDMETHOD.


  METHOD _routes.

    zcl_flifm_gui=>get_gui( EXPORTING
                              iv_route = is_route_data-route
                              io_parent = is_route_data-parent )->render( iv_menu    = is_route_data-menu
                                                                          iv_company = is_route_data-company
                                                                          iv_action  = is_route_data-action ).

  ENDMETHOD.
ENDCLASS.
