package com.usoftchina.bi.server.controller.dashboard;

import com.usoftchina.bi.auth.annotation.Auth;
import com.usoftchina.bi.core.base.RepCode;
import com.usoftchina.bi.core.base.RepEntity;
import com.usoftchina.bi.server.model.pojo.annotation.CheckToken;
import com.usoftchina.bi.server.model.vo.configVo.DashBoardMenuInfo;
import com.usoftchina.bi.server.model.vo.configVo.DashBoardUpdateMenuInfo;
import com.usoftchina.bi.server.service.dashboard.DashBoardMenuService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author chenwei
 * @Date 2019-04-19
 */
@RestController
@RequestMapping("/dashboard/menu")
@Api(description = "看板目录相关接口")
public class DashboardMenuController {

    @Autowired
    private DashBoardMenuService dashBoardMenuService;

    @GetMapping("/list")
    @CheckToken
    @ApiOperation(value = "目录列表", notes = "目录列表", response = RepEntity.class)
    public RepEntity list(@RequestHeader String token){
        return new RepEntity(RepCode.success, dashBoardMenuService.list(token));
    }

    @PostMapping("/save")
    @CheckToken
    @Auth(user = "admin")
    @ApiOperation(value = "保存目录", notes = "保存看板目录", response = RepEntity.class)
    public RepEntity save(@RequestHeader String token, @RequestBody DashBoardMenuInfo dashBoardMenuInfo){
        return new RepEntity(RepCode.success, dashBoardMenuService.save(dashBoardMenuInfo));
    }

    @PostMapping("/update")
    @CheckToken
    @Auth(user = "admin")
    @ApiOperation(value = "更新目录", notes = "更新看板目录", response = RepEntity.class)
    public RepEntity update(@RequestHeader String token, @RequestBody DashBoardMenuInfo dashBoardMenuInfo){
        dashBoardMenuService.update(dashBoardMenuInfo);
        return new RepEntity(RepCode.success);
    }

    @PostMapping("/delete/{id}")
    @CheckToken
    @Auth(user = "admin")
    @ApiOperation(value = "删除目录", notes = "删除看板目录", response = RepEntity.class)
    public RepEntity delete(@RequestHeader String token, @PathVariable("id") Long id){
        dashBoardMenuService.deleteById(id);
        return new RepEntity(RepCode.success);
    }

    @PostMapping("/update/dashboard")
    @CheckToken
    @Auth(user = "admin")
    @ApiOperation(value = "更新看板目录", notes = "更新看板目录", response = RepEntity.class)
    public RepEntity updateDashBoard(@RequestHeader String token, @RequestBody DashBoardUpdateMenuInfo dashBoardUpdateMenuInfo){
        dashBoardMenuService.updateDashBoardMenu(dashBoardUpdateMenuInfo);
        return new RepEntity(RepCode.success);
    }

    @GetMapping("/list/{menuId}")
    @CheckToken
    @ApiOperation(value = "获得目录下的所有报表", notes = "通过MenuId获得目录下的所有报表", response = RepEntity.class)
    public RepEntity getDashBoardByMenuId(@RequestHeader String token, @PathVariable("menuId") int menuId){
        return dashBoardMenuService.getDashBoardByMenuId(token, menuId);
    }
}
