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

import com.tzld.piaoquan.api.annotation.JwtIgnore;
import com.tzld.piaoquan.api.annotation.RateLimit;
import com.tzld.piaoquan.api.annotation.RequireSign;
import com.tzld.piaoquan.api.model.param.IdParam;
import com.tzld.piaoquan.api.model.param.contentplatform.*;
import com.tzld.piaoquan.api.model.vo.contentplatform.GzhPlanItemVO;
import com.tzld.piaoquan.api.model.vo.contentplatform.QwPlanItemVO;
import com.tzld.piaoquan.api.model.vo.contentplatform.XcxPlanItemVO;
import com.tzld.piaoquan.api.model.vo.contentplatform.VideoContentItemVO;
import com.tzld.piaoquan.api.service.contentplatform.ContentPlatformPlanService;
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/plan")
@CrossOrigin(origins = "*")
public class ContentPlatformPlanController {

    @Autowired
    ContentPlatformPlanService planService;

    @ApiOperation(value = "公众号计划列表")
    @PostMapping("/gzh/list")
    @RequireSign
    public CommonResponse<Page<GzhPlanItemVO>> gzhPlanList(@RequestBody GzhPlanListParam param) {
        return CommonResponse.success(planService.gzhPlanList(param));
    }

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

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

    @ApiOperation(value = "公众号计划 平台发布开关修改")
    @PostMapping("/gzh/updateStagePublishStatus")
    @RequireSign
    public CommonResponse<Void> gzhUpdateStagePublishStatus(@RequestBody GzhPlanStagePublishStatusUpdateParam param) {
        planService.gzhUpdateStagePublishStatus(param.getId(), param.getStagePublishStatus());
        return CommonResponse.success();
    }

    @ApiOperation(value = "发布内容视频列表")
    @PostMapping("/videoContentList")
    @RateLimit(timeWindow = 30, maxRequests = 10, limitByAccount = true, message = "请求过于频繁，请稍后再试")
    @RequireSign
    public CommonResponse<Page<VideoContentItemVO>> getVideoContentList(@RequestBody VideoContentListParam param) {
        return CommonResponse.success(planService.getVideoContentList(param));
    }

    @ApiOperation(value = "向量匹配视频列表")
    @PostMapping("/vector/videoContentList")
    @RateLimit(timeWindow = 30, maxRequests = 10, limitByAccount = true, message = "请求过于频繁，请稍后再试")
    @RequireSign
    public CommonResponse<Page<VideoContentItemVO>> getVectorVideoContentList(@RequestBody VideoContentListParam param) {
        return CommonResponse.success(planService.getVectorVideoContentList(param));
    }

    @ApiOperation(value = "个人上传发布内容视频列表")
    @PostMapping("/upload/videoContentList")
    @RateLimit(timeWindow = 30, maxRequests = 10, limitByAccount = true, message = "请求过于频繁，请稍后再试")
    @RequireSign
    public CommonResponse<Page<VideoContentItemVO>> getUploadVideoContentList(@RequestBody VideoContentListParam param) {
        return CommonResponse.success(planService.getUploadVideoContentList(param));
    }

    @ApiOperation(value = "需求匹配视频列表")
    @PostMapping("/demand/videoContentList")
    @RateLimit(timeWindow = 30, maxRequests = 10, limitByAccount = true, message = "请求过于频繁，请稍后再试")
    @RequireSign
    public CommonResponse<Page<VideoContentItemVO>> getDemandVideoContentList(@RequestBody VideoContentListParam param) {
        return CommonResponse.success(planService.getDemandVideoContentList(param));
    }

    @ApiOperation(value = "发布内容视频品类列表")
    @GetMapping("/videoContentCategoryList")
    public CommonResponse<List<String>> getVideoContentCategoryList(String category) {
        return CommonResponse.success(planService.getVideoContentCategoryList(category));
    }

    @ApiOperation(value = "发布内容视频封面截帧列表")
    @PostMapping("/videoContentCoverFrameList")
    @RequireSign
    public CommonResponse<List<String>> getVideoContentCoverFrameList(@RequestBody VideoContentCoverFrameParam param) {
        return CommonResponse.success(planService.getVideoContentCoverFrameList(param));
    }

    @ApiOperation(value = "企微计划列表")
    @PostMapping("/qw/list")
    @RequireSign
    public CommonResponse<Page<QwPlanItemVO>> qwPlanList(@RequestBody QwPlanListParam param) {
        return CommonResponse.success(planService.qwPlanList(param));
    }

    @ApiOperation(value = "企微计划列表导出")
    @PostMapping("/qw/export")
    @RequireSign
    public CommonResponse<String> qwPlanExport(@RequestBody QwPlanListParam param) {
        return CommonResponse.success(planService.qwPlanExport(param));
    }

    @ApiOperation(value = "企微计划 创建/更新")
    @PostMapping("/qw/save")
    @RequireSign
    public CommonResponse<List<QwPlanItemVO>> qwPlanSave(@RequestBody QwPlanSaveParam param) {
        return CommonResponse.success(planService.qwPlanSave(param));
    }

    @ApiOperation(value = "企微计划 删除")
    @PostMapping("/qw/delete")
    @RequireSign
    public CommonResponse<Void> qwPlanDelete(@RequestBody IdParam<Long> param) {
        planService.qwPlanDelete(param.getId());
        return CommonResponse.success();
    }

    @ApiOperation(value = "获取分享二维码")
    @GetMapping("/qw/getSharePic")
    public CommonResponse<String> getQwSharePic(@RequestParam String pageUrl) {
        return CommonResponse.success(planService.getSharePic(pageUrl));
    }

    @ApiOperation(value = "小程序计划列表")
    @PostMapping("/xcx/list")
    @RequireSign
    public CommonResponse<Page<XcxPlanItemVO>> xcxPlanList(@RequestBody XcxPlanListParam param) {
        return CommonResponse.success(planService.xcxPlanList(param));
    }

    @ApiOperation(value = "小程序计划列表导出")
    @PostMapping("/xcx/export")
    @RequireSign
    public CommonResponse<String> xcxPlanExport(@RequestBody XcxPlanListParam param) {
        return CommonResponse.success(planService.xcxPlanExport(param));
    }

    @ApiOperation(value = "小程序计划 创建/更新")
    @PostMapping("/xcx/save")
    @RequireSign
    public CommonResponse<List<XcxPlanItemVO>> xcxPlanSave(@RequestBody XcxPlanSaveParam param) {
        return CommonResponse.success(planService.xcxPlanSave(param));
    }

    @ApiOperation(value = "小程序计划 删除")
    @PostMapping("/xcx/delete")
    @RequireSign
    public CommonResponse<Void> xcxPlanDelete(@RequestBody IdParam<Long> param) {
        planService.xcxPlanDelete(param.getId());
        return CommonResponse.success();
    }

    @ApiOperation(value = "小程序计划 多链接生成(同 video 复制 N 份)")
    @PostMapping("/xcx/multiLink")
    @RequireSign
    public CommonResponse<List<XcxPlanItemVO>> xcxPlanMultiLink(@RequestBody XcxPlanMultiLinkParam param) {
        return CommonResponse.success(planService.xcxPlanMultiLink(param));
    }

    @ApiOperation(value = "获取小程序分享二维码")
    @GetMapping("/xcx/getSharePic")
    public CommonResponse<String> getXcxSharePic(@RequestParam String pageUrl) {
        return CommonResponse.success(planService.getSharePic(pageUrl));
    }

    @ApiOperation(value = "小程序投流-人群包列表")
    @GetMapping("/xcx/getAudiencePackageList")
    public CommonResponse<List<String>> getXcxAudiencePackageList() {
        return CommonResponse.success(planService.getXcxAudiencePackageList());
    }

    @ApiOperation(value = "获取分享二维码")
    @GetMapping("/getSharePic")
    public CommonResponse<String> getSharePic(@RequestParam String pageUrl) {
        return CommonResponse.success(planService.getSharePic(pageUrl));
    }

    @ApiOperation(value = "获取分享链接")
    @GetMapping("/getShareUrlLink")
    @JwtIgnore
    public CommonResponse<String> getShareUrlLink(@RequestParam String pageUrl) {
        return CommonResponse.success(planService.getShareUrlLink(pageUrl));
    }
}
