package sgc.portal.com.sym.mnu.web;

import sgc.portal.base.model.Yfvrprg;
import sgc.portal.base.util.EasyHashMap;
import sgc.portal.base.util.ValidChk;
import sgc.portal.com.sym.mnu.service.MenuService;
import sgc.portal.com.sym.user.model.UserDetails;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * The type Menu controller.
 */
@RestController
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * Select menu list list.
     *
     * @param userDetails  the user details
     * @param userDetails2 the user details 2
     * @return the list
     */
    @PostMapping("/menu/selectMenuListKo")
    public List<EasyHashMap<String, Object>> selectMenuListKo(UserDetails userDetails, @RequestBody UserDetails userDetails2) {
        if (!ValidChk.isStringDouble(userDetails.getUserId()) || !ValidChk.isStringDouble(userDetails2.getUserId())) {
            return null;
        }
        if (userDetails.isAsMember()) {
          	return menuService.selectMenuAsListKo(userDetails.getAuthorities(), userDetails2.getTopMenu(), userDetails2.getPrgNm());
        } else {
        	return menuService.selectMenuListKo(userDetails.getAuthorities(), userDetails2.getTopMenu(), userDetails2.getPrgNm());
        }
    }
    
    @PostMapping("/menu/selectMenuListEn")
    public List<EasyHashMap<String, Object>> selectMenuListEn(UserDetails userDetails, @RequestBody UserDetails userDetails2) {
        if (!ValidChk.isStringDouble(userDetails.getUserId()) || !ValidChk.isStringDouble(userDetails2.getUserId())) {
            return null;
        }
        if (userDetails.isAsMember()) {
          	return menuService.selectMenuAsListEn(userDetails.getAuthorities(), userDetails2.getTopMenu(), userDetails2.getPrgNm());
        } else {
        	return menuService.selectMenuListEn(userDetails.getAuthorities(), userDetails2.getTopMenu(), userDetails2.getPrgNm());
        }
    }

    /**
     * Select top menu list list.
     *
     * @param userDetails the user details
     * @return the list
     */
    @GetMapping("/menu/selectTopMenuListKo")
    public List<EasyHashMap<String, Object>> selectTopMenuListKo(UserDetails userDetails) {
        if (userDetails.isAsMember()) {
        	return menuService.selectTopMenuAsListKo(userDetails);
        } else {
        	return menuService.selectTopMenuListKo(userDetails);
        }
    }
    
    @GetMapping("/menu/selectTopMenuListEn")
    public List<EasyHashMap<String, Object>> selectTopMenuListEnEn(UserDetails userDetails) {
        if (userDetails.isAsMember()) {
        	return menuService.selectTopMenuAsListEn(userDetails);
        } else {
        	return menuService.selectTopMenuListEn(userDetails);
        }
    }

    /**
     * Select bock menu list list.
     *
     * @param yfvrprgs the yfvrprgs
     * @return the list
     */
//즐겨찾기
    @PostMapping("/menu/selectBockMenuList")
    public List<EasyHashMap<String, Object>> selectBockMenuList(@RequestBody Yfvrprg yfvrprgs) {
        return menuService.selectBockMenuList(yfvrprgs);
    }
}