package com.tzld.piaoquan.api.controller.contentplatform;

import com.tzld.piaoquan.api.annotation.RequireSign;
import com.tzld.piaoquan.api.model.param.IdParam;
import com.tzld.piaoquan.api.model.param.contentplatform.CooperateAccountListParam;
import com.tzld.piaoquan.api.model.param.contentplatform.CooperateAccountSaveParam;
import com.tzld.piaoquan.api.model.param.contentplatform.GzhAuthResultParam;
import com.tzld.piaoquan.api.model.vo.contentplatform.CooperateAccountItemVO;
import com.tzld.piaoquan.api.model.vo.contentplatform.GenerateQrcodeVO;
import com.tzld.piaoquan.api.model.vo.contentplatform.GzhAccountItem;
import com.tzld.piaoquan.api.model.vo.contentplatform.GzhAuthResultVO;
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformCooperateAccountService;
import com.tzld.piaoquan.growth.common.common.base.CommonResponse;
import com.tzld.piaoquan.growth.common.utils.page.Page;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/contentPlatform/cooperateAccount")
@CrossOrigin(origins = "*")
public class ContentPlatformCooperateAccountController {

    @Autowired
    ContentPlatformCooperateAccountService cooperateAccountService;

    @ApiOperation(value = "公众号列表")
    @PostMapping("/gzh/list")
    @RequireSign
    public CommonResponse<Page<CooperateAccountItemVO>> gzhList(@RequestBody CooperateAccountListParam param) {
        return CommonResponse.success(cooperateAccountService.gzhList(param));
    }

    @ApiOperation(value = "公众号创建/更新")
    @PostMapping("/gzh/save")
    @RequireSign
    public CommonResponse<Void> gzhSave(@RequestBody CooperateAccountSaveParam param) {
        cooperateAccountService.gzhSave(param);
        return CommonResponse.success();
    }

    @ApiOperation(value = "公众号授权二维码获取")
    @PostMapping("/gzh/getAuthQrCode")
    @RequireSign
    public CommonResponse<GenerateQrcodeVO> getGzhAuthQrCode(@RequestBody GzhAuthResultParam param) {
        return CommonResponse.success(cooperateAccountService.getGzhAuthQrCode(param));
    }

    @ApiOperation(value = "公众号授权结果获取")
    @PostMapping("/gzh/getAuthResult")
    @RequireSign
    public CommonResponse<GzhAuthResultVO> getGzhAuthResult(@RequestBody GzhAuthResultParam param) {
        return CommonResponse.success(cooperateAccountService.getGzhAuthResult(param));
    }

    @ApiOperation(value = "内容类别下拉框")
    @GetMapping("/gzh/getContentType")
    public CommonResponse<List<String>> getGzhContentType() {
        return CommonResponse.success(cooperateAccountService.getGzhContentType());
    }

    @ApiOperation(value = "公众号下拉框")
    @GetMapping("/gzh/accountList")
    public CommonResponse<List<GzhAccountItem>> getGzhAccountList(@RequestParam(required = false) Integer accountType,
                                                                  @RequestParam(required = false) String name) {
        return CommonResponse.success(cooperateAccountService.getGzhAccountList(accountType, name));
    }

    @ApiOperation(value = "公众号删除")
    @PostMapping("/gzh/delete")
    @RequireSign
    public CommonResponse<Void> gzhDelete(@RequestBody IdParam<Long> param) {
        cooperateAccountService.gzhDelete(param.getId());
        return CommonResponse.success();
    }
}
