package com.njcn.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.njcn.common.pojo.annotation.OperateInfo;
import com.njcn.common.pojo.enums.common.LogEnum;
import com.njcn.common.pojo.enums.response.CommonResponseEnum;
import com.njcn.common.pojo.exception.BusinessException;
import com.njcn.common.pojo.response.HttpResult;
import com.njcn.common.utils.HttpResultUtil;
import com.njcn.system.pojo.param.PqDashboardPageParam;
import com.njcn.system.pojo.po.PqDashboardPage;
import com.njcn.system.pojo.vo.PqDashboardPageVO;
import com.njcn.system.service.PqDashboardPageService;
import com.njcn.user.enums.UserResponseEnum;
import com.njcn.web.controller.BaseController;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Objects;

/**
 * Description:
 * Date: 2025/05/23  下午 3:30【需求编号】
 *
 * @author clam
 * @version V1.0.0
 */
@Slf4j
@Api(tags = "驾驶舱配置")
@RestController
@RequiredArgsConstructor
@RequestMapping("/dashboard")
public class PqDashboardPageController extends BaseController {

    private final PqDashboardPageService pqDashboardPageService;
    @PostMapping("/addDashboard")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("新增驾驶舱页面")
    public HttpResult<Boolean> addDashboard(@RequestBody PqDashboardPageParam pqDashboardPageParam){
        log.info("新增驾驶舱页面");
        String methodDescribe = getMethodDescribe("addDashboard");
        Boolean result = pqDashboardPageService.addDashboard(pqDashboardPageParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("/updateDashboard")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("修改驾驶舱页面")
    public HttpResult<Boolean> updateDashboard(@RequestBody PqDashboardPageParam.UpdatePqDashboardPageParam updatePqDashboardPageParam){
        log.info("修改驾驶舱页面");
        String methodDescribe = getMethodDescribe("updateDashboard");
        Boolean result = pqDashboardPageService.updateDashboard(updatePqDashboardPageParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("/deleteDashboard")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("删除驾驶舱页面")
    public HttpResult<Boolean> deleteDashboard(@RequestParam("id") String id){
        log.info("删除驾驶舱页面");
        String methodDescribe = getMethodDescribe("deleteDashboard");
        Boolean result = pqDashboardPageService.removeById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("/queryById")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询驾驶舱页面")
    public HttpResult<PqDashboardPageVO> queryById(@RequestParam("id") String id){
        log.info("查询驾驶舱页面");
        String methodDescribe = getMethodDescribe("queryById");
        PqDashboardPageVO result = pqDashboardPageService.queryById(id);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }
    @PostMapping("/activatePage")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("激活的驾驶舱页面")
    public HttpResult<Boolean> activatePage(@RequestParam("id") String id,@RequestParam("state") Integer state){
        log.info("激活的驾驶舱页面");
        String methodDescribe = getMethodDescribe("activatePage");
        Boolean result = pqDashboardPageService.activatePage(id,state);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("/scopePage")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("全局的驾驶舱页面")
    public HttpResult<Boolean> scopePage(@RequestParam("id") String id,@RequestParam("userId") String userId){
        log.info("全局的驾驶舱页面");
        String methodDescribe = getMethodDescribe("scopePage");
        Boolean result = pqDashboardPageService.scopePage(id,userId);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("/queryActivatePage")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("查询激活的驾驶舱页面")
    public HttpResult<PqDashboardPageVO> queryActivatePage(){
        log.info("查询激活的驾驶舱页面");
        String methodDescribe = getMethodDescribe("queryActivatePage");
        PqDashboardPageVO vo = new PqDashboardPageVO();
        PqDashboardPage result = pqDashboardPageService.lambdaQuery().eq(PqDashboardPage::getState,1).one();
        if(Objects.isNull(result)){
            throw new BusinessException("暂无激活的驾驶舱页面");
        }
        BeanUtils.copyProperties(result,vo);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, vo, methodDescribe);
    }

    @PostMapping("/queryPage")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("分页查询")
    public HttpResult<Page<PqDashboardPageVO>> queryPage(@RequestBody PqDashboardPageParam.PqDashboardPageQueryParam pqDashboardPageQueryParam){
        log.info("分页查询");
        String methodDescribe = getMethodDescribe("queryPage");
        Page<PqDashboardPageVO> result = pqDashboardPageService.queryPage(pqDashboardPageQueryParam);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("/queryByPagePath")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据页面路由查询数据")
    public HttpResult<PqDashboardPageVO> queryByPagePath(@RequestParam("pagePath") String pagePath){
        String methodDescribe = getMethodDescribe("queryByPagePath");
        PqDashboardPageVO result = pqDashboardPageService.queryByPagePath(pagePath);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

    @PostMapping("/getDashboardPageByUserId")
    @OperateInfo(info = LogEnum.BUSINESS_COMMON)
    @ApiOperation("根据用户id查询用户驾驶舱")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户id", required = true),
            @ApiImplicitParam(name = "state", value = "状态", required = true)
    })
    public HttpResult<List<PqDashboardPage>> getDashboardPageByUserId(@RequestParam("id") String id,@RequestParam("state") boolean state){
        String methodDescribe = getMethodDescribe("getDashboardPageByUserId");
        List<PqDashboardPage> result = pqDashboardPageService.getDashboardPageByUserId(id,state);
        return HttpResultUtil.assembleCommonResponseResult(CommonResponseEnum.SUCCESS, result, methodDescribe);
    }

}
