package com.pcloud.book.pcloudkeyword.facade;

import com.pcloud.book.pcloudkeyword.biz.PcloudRobotBiz;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobot;
import com.pcloud.book.pcloudkeyword.entity.PcloudRobotWelcome;
import com.pcloud.common.dto.ResponseDto;
import com.pcloud.common.exceptions.BizException;
import com.pcloud.common.permission.PermissionException;
import com.pcloud.common.utils.SessionUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api("全平台个人号配置")
@RestController("pcloudRobot")
@RequestMapping("pcloudRobotFacade")
public class PcloudRobotFacade {

    @Autowired
    private PcloudRobotBiz pcloudRobotBiz;

    @ApiOperation("新增全平台机器人")
    @PostMapping("/createPcloudRobot")
    ResponseDto<?> createPcloudRobot(
            @RequestHeader("token") @ApiParam("token信息") String token,
            @RequestBody @ApiParam("全平台个人号") PcloudRobot pcloudRobot
    ) throws BizException, PermissionException {
        SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
        pcloudRobotBiz.createPcloudRobot(pcloudRobot);
        return new ResponseDto<>();
    }

    @ApiOperation("修改全平台机器人")
    @PostMapping("/updatePcloudRobot")
    ResponseDto<?> updatePcloudRobot(
            @RequestHeader("token") @ApiParam("token信息") String token,
            @RequestBody @ApiParam("全平台个人号") PcloudRobot pcloudRobot
    ) throws BizException, PermissionException {
        SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
        pcloudRobotBiz.updatePcloudRobot(pcloudRobot);
        return new ResponseDto<>();
    }

    @ApiOperation("获取全平台个人号列表")
    @GetMapping("/getPcloudRobotList")
    ResponseDto<?> getPcloudRobotList(
            @RequestHeader("token") @ApiParam("token信息") String token,
            @RequestParam(value = "nickName", required = false) @ApiParam("昵称") String nickName,
            @RequestParam("currentPage") Integer currentPage,
            @RequestParam("numPerPage") Integer numPerPage
    ) throws BizException, PermissionException{
        SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
        return new ResponseDto<>(pcloudRobotBiz.getPcloudRobotList(nickName,currentPage,numPerPage));
    }


    @ApiOperation("更新全平台个人号欢迎语")
    @PostMapping("/batchUpdatePcloudRobotWelcome")
    ResponseDto<?> batchUpdatePcloudRobotWelcome(
            @RequestHeader("token") @ApiParam("token信息") String token,
            @RequestBody @ApiParam("全平台个人号欢迎语列表") List<PcloudRobotWelcome> robotWelcomeList
    ) throws BizException, PermissionException {
        SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
        pcloudRobotBiz.batchUpdatePcloudRobotWelcome(robotWelcomeList);
        return new ResponseDto<>();
    }

    @ApiOperation("获取全平台个人号信息")
    @GetMapping("/getPcloudRobot")
    ResponseDto<?> getPcloudRobot(
            @RequestHeader("token") @ApiParam("token信息") String token,
            @RequestParam("id") Long id
    ) throws BizException, PermissionException{
        SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
        return new ResponseDto<>(pcloudRobotBiz.getPcloudRobot(id));
    }

    @ApiOperation("小号关联关键词分类")
    @GetMapping("/relateKeywordClassify")
    ResponseDto<?> relateKeywordClassify(
            @RequestHeader("token") @ApiParam("token信息") String token,
            @RequestParam(value = "pcloudRobotId", required = false) @ApiParam("平台小号ID") Long pcloudRobotId,
            @RequestParam(value = "keywordClassifyId", required = false) @ApiParam("关键分类ID") Long keywordClassifyId
    ) throws BizException, PermissionException{
        SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
        pcloudRobotBiz.relateKeywordClassify(pcloudRobotId, keywordClassifyId);
        return new ResponseDto<>();
    }

    @ApiOperation("根据类型获取全平台个人号信息")
    @GetMapping("/getPcloudRobotByType")
    ResponseDto<?> getPcloudRobotByType(
            @RequestParam("robotType") Integer robotType
    ) throws BizException, PermissionException{
        return new ResponseDto<>(pcloudRobotBiz.getPcloudRobotByType(robotType));
    }

    @ApiOperation("获取全平台分类模板列表")
    @GetMapping("/listClassifyTemplate")
    ResponseDto<?> listClassifyTemplate(
            @RequestHeader("token") @ApiParam("token信息") String token,
            @RequestParam(value = "classifyId", required = false) @ApiParam("昵称") Integer classifyId,
            @RequestParam("currentPage") Integer currentPage,
            @RequestParam("numPerPage") Integer numPerPage
    ) throws BizException, PermissionException{
        SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
        return new ResponseDto<>(pcloudRobotBiz.listClassifyTemplate(classifyId,currentPage,numPerPage));
    }

    @ApiOperation("小号关联关键词分类")
    @GetMapping("/openTemplate")
    ResponseDto<?> openTemplate(
            @RequestHeader("token") @ApiParam("token信息") String token,
            @RequestParam(value = "classifyId", required = false) @ApiParam("分类ID") Integer classifyId,
            @RequestParam(value = "templateId", required = false) @ApiParam("模板ID") Long templateId
    ) throws BizException, PermissionException{
        SessionUtil.getVlaue(token, SessionUtil.PARTY_ID);
        pcloudRobotBiz.openTemplate(classifyId, templateId);
        return new ResponseDto<>();
    }

    @ApiOperation("根据分类ID获取模板信息")
    @GetMapping("/getTemplateByClassifyId")
    ResponseDto<?> getTemplateByClassifyId(
            @RequestParam("classifyId") Integer classifyId
    ) throws BizException, PermissionException{
        return new ResponseDto<>(pcloudRobotBiz.getTemplateByClassifyId(classifyId));
    }
}
