package com.eactive.eai.rms.common.acl.menu;

import java.util.List;
import java.util.stream.Collectors;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.eactive.eai.rms.common.acl.menu.ui.LeftMenuUI;
import com.eactive.eai.rms.common.acl.menu.ui.MenuUI;
import com.eactive.eai.rms.data.entity.man.menu.MenuService;

@Service
@Transactional(transactionManager = "transactionManagerForEMS")
public class MenuRenderService {

	private MenuService menuService;

	@Autowired
	public MenuRenderService(MenuService menuService) {
		this.menuService = menuService;
	}

   public LeftMenuUI leftMenuList(String lv3MenuId, List<String> roleIds, List<String> appCodes, String serviceType) {
		LeftMenuUI leftMenuUI = new LeftMenuUI();

		String menuName = menuService.getMenuName(lv3MenuId);
		leftMenuUI.setMenuName(menuName);

		// 해당 메뉴 리스트 가져오기
      List<MenuUI> list = menuService.getLeftMenuList(lv3MenuId, roleIds, appCodes, serviceType).stream().map(menu -> {
			MenuUI menuUI = new MenuUI();
			menuUI.setMenuUrl(menu.getMenuUrl());
			menuUI.setMenuId(menu.getMenuId());
			menuUI.setMenuName(menu.getMenuName());
			return menuUI;
		}).collect(Collectors.toList());

		leftMenuUI.setMenuList(list);
		return leftMenuUI;
	}

}
