package com.njcn.product.system.theme.controller;


import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.constant.OperateType;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.common.utils.LogUtil;

import com.njcn.product.system.theme.pojo.vo.FunctionVO;
import com.njcn.product.system.theme.service.IFunctionService;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hongawen
 * @since 2021-12-13
 */
@Validated
@Slf4j
@RestController
@RequestMapping("/function")
@Api(tags = "菜单信息管理")
@AllArgsConstructor
public class FunctionController extends BaseController {

    private final IFunctionService functionService;

//    /**
//     * 新增资源
//     * @param functionParam 资源数据
//     */
//    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.ADD)
//    @PostMapping("/add")
//    @ApiOperation("新增菜单")
//    @ApiImplicitParam(name = "functionParam", value = "菜单数据", required = true)
//    public HttpResult<Boolean> add(@RequestBody @Validated FunctionParam functionParam) {
//        String methodDescribe = getMethodDescribe("add");
//        LogUtil.njcnDebug(log, "{}，菜单数据为：{}", methodDescribe, functionParam);
//        boolean result = functionService.addFunction(functionParam);
//        if (result) {
//            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
//        } else {
//            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
//        }
//    }
//
//    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.UPDATE)
//    @PutMapping("/update")
//    @ApiOperation("修改菜单")
//    @ApiImplicitParam(name = "functionParam", value = "菜单数据", required = true)
//    public HttpResult<Boolean> update(@RequestBody @Validated FunctionParam.FunctionUpdateParam functionParam) {
//        String methodDescribe = getMethodDescribe("update");
//        LogUtil.njcnDebug(log,  "{},更新的菜单信息为：{}", methodDescribe,functionParam);
//        boolean result = functionService.updateFunction(functionParam);
//        if (result){
//            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
//        } else {
//            return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.FAIL, false, methodDescribe);
//        }
//    }
//
//    @OperateInfo(info = LogEnum.SYSTEM_COMMON, operateType = OperateType.DELETE)
//    @DeleteMapping("/delete")
//    @ApiOperation("删除菜单")
//    @ApiImplicitParam(name = "id", value = "菜单id", required = true)
//    public HttpResult<Boolean> delete(@RequestParam @Validated String id) {
//        String methodDescribe = getMethodDescribe("delete");
//        LogUtil.njcnDebug(log,  "{},删除的菜单id为：{}", methodDescribe,id);
//        functionService.deleteFunction(id);
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, true, methodDescribe);
//    }
//
//    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
//    @GetMapping("/functionTree")
//    @ApiOperation("菜单树")
//    public HttpResult<List<FunctionVO>> getFunctionTree() {
//        String methodDescribe = getMethodDescribe("getFunctionTree");
//        List<FunctionVO> list = functionService.getFunctionTree();
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,list,methodDescribe);
//    }
//
//    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
//    @GetMapping("/getFunctionById")
//    @ApiOperation("菜单详情")
//    @ApiImplicitParam(name = "id", value = "菜单id", required = true)
//    public HttpResult<Function> getFunctionById(String id){
//        String methodDescribe = getMethodDescribe("getFunctionById");
//        LogUtil.njcnDebug(log,  "{},菜单id为：{}", methodDescribe,id);
//        Function function = functionService.getFunctionById(id);
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,function,methodDescribe);
//    }
//
//    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
//    @GetMapping("/getButtonById")
//    @ApiOperation("获取按钮")
//    @ApiImplicitParam(name = "id", value = "菜单id", required = true)
//    public HttpResult<List<Function>> getButtonById(String id){
//        String methodDescribe = getMethodDescribe("getButtonById");
//        LogUtil.njcnDebug(log,  "{},菜单id为：{}", methodDescribe,id);
//        List<Function> list = functionService.getButtonsById(id);
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,list,methodDescribe);
//    }


    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
    @GetMapping("/getRouteMenu")
    @ApiOperation("路由菜单")
    public HttpResult<List<FunctionVO>> getRouteMenu(){
        String methodDescribe = getMethodDescribe("getRouteMenu");
        List<FunctionVO> list = functionService.getRouteMenu();
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,list,methodDescribe);
    }
//
//    @OperateInfo(operateType = OperateType.UPDATE,info = LogEnum.SYSTEM_MEDIUM)
//    @PostMapping("/assignFunctionByRoleIndexes")
//    @ApiOperation("角色分配菜单")
//    @ApiImplicitParam(name = "roleFunctionComponent", value = "角色信息", required = true)
//    public HttpResult<Boolean> assignFunctionByRoleIndexes(@RequestBody @Validated RoleParam.RoleFunctionComponent roleFunctionComponent) {
//        String methodDescribe = getMethodDescribe("assignFunctionByRoleIndexes");
//        LogUtil.njcnDebug(log,  "{},传入的角色id和资源id集合为：{}", methodDescribe,roleFunctionComponent);
//        boolean result = functionService.updateRoleComponent(roleFunctionComponent);
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
//    }
//
//    @OperateInfo(info = LogEnum.SYSTEM_COMMON)
//    @GetMapping("/userFunctionTree")
//    @ApiOperation("用户菜单树")
//    public HttpResult<List<FunctionVO>> getUserFunctionTree() {
//        String methodDescribe = getMethodDescribe("getUserFunctionTree");
//        List<FunctionVO> list = functionService.getUserFunctionTree();
//        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS,list,methodDescribe);
//    }
}

