package com.tzld.piaoquan.api.controller.wecom.thirdpart;

import com.tzld.piaoquan.api.model.param.wecom.thirdpart.*;
import com.tzld.piaoquan.api.model.vo.IdNameVO;
import com.tzld.piaoquan.api.model.vo.contentplatform.AccountQrCodeVO;
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.CheckPushAccountExistVO;
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountConfigVO;
import com.tzld.piaoquan.api.model.vo.wecom.thirdpart.ThirdPartyAccountVO;
import com.tzld.piaoquan.api.service.wecom.thirdparty.WeComThirdPartyAccountService;
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
import com.tzld.piaoquan.growth.common.utils.page.Page;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/wecom/thirdparty/account")
@CrossOrigin(origins = "*")
public class WeComThirdPartyAccountController {

    @Autowired
    private WeComThirdPartyAccountService service;

    @ApiOperation(value = "获取登录二维码")
    @GetMapping("/getQrCode")
    public CommonResponse<AccountQrCodeVO> getQrCode(@RequestParam(required = false) Long id) {
        return CommonResponse.success(service.getQrCode(id));
    }

    @ApiOperation(value = "检查登录状态")
    @GetMapping("/checkLogin")
    public CommonResponse<Integer> checkLogin(@RequestParam String uuid) {
        return CommonResponse.success(service.checkLogin(uuid));
    }

    @ApiOperation(value = "设置验证码")
    @PostMapping("/setCheckCode")
    public CommonResponse<Void> setCheckCode(@RequestBody CheckCodeRequest param) {
        service.setCheckCode(param);
        return CommonResponse.success();
    }

    @ApiOperation(value = "账号列表")
    @PostMapping("/list")
    public CommonResponse<Page<ThirdPartyAccountVO>> list(@RequestBody ThirdPartyAccountListParam param) {
        return CommonResponse.success(service.list(param));
    }

    @ApiOperation(value = "获取推送人员列表")
    @GetMapping("/getPushAccountList")
    public CommonResponse<List<IdNameVO<Long>>> getPushAccountList(@RequestParam Long accountId, @RequestParam(required = false) String name) {
        return CommonResponse.success(service.getPushAccountList(accountId, name));
    }

    @ApiOperation(value = "获取账号配置")
    @PostMapping("/getAccountConfig")
    public CommonResponse<ThirdPartyAccountConfigVO> getAccountConfig(@RequestBody ThirdPartyConfigGetParam param) {
        return CommonResponse.success(service.getAccountConfig(param));
    }

    @ApiOperation(value = "检查推送人员是否在所有群内")
    @PostMapping("/checkPushAccountExist")
    public CommonResponse<CheckPushAccountExistVO> checkPushAccountExist(@RequestBody ThirdPartyAccountConfigParam param) {
        return CommonResponse.success(service.checkPushAccountExist(param));
    }

    @ApiOperation(value = "账号配置保存")
    @PostMapping("/saveAccountConfig")
    public CommonResponse<Void> saveAccountConfig(@RequestBody ThirdPartyAccountConfigParam param) {
        service.saveAccountConfig(param);
        return CommonResponse.success();
    }

    @ApiOperation(value = "登出")
    @PostMapping("/logout")
    public CommonResponse<Void> logout(@RequestBody ThirdPartyAccountLogOutParam param) {
        service.logout(param);
        return CommonResponse.success();
    }

    @ApiOperation(value = "初始化账号配置")
    @PostMapping("/initAccountConfig")
    public CommonResponse<Void> initAccountConfig() {
        service.initAccountConfig();
        return CommonResponse.success();
    }

}
