package com.zhongshu.card.server.core.controller.projectAbout;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.ProjectOidParam;
import com.zhongshu.card.client.model.feign.ProjectWxPayParam;
import com.zhongshu.card.client.model.projectAbout.ProjectWeChatInfoModel;
import com.zhongshu.card.client.model.projectAbout.ProjectWeChatInfoParam;
import com.zhongshu.card.client.model.xcx.ProjectXcxModel;
import com.zhongshu.card.server.core.service.projectAbout.ProjectWeChatInfoService;
import io.swagger.v3.oas.annotations.Hidden;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * 项目的微信小程序设置
 *
 * @author TRX
 * @date 2024/7/26
 */
@RestController
@RequestMapping("/project/projectWeChatInfo")
@Tag(name = "项目-微信小程序设置")
public class ProjectWeChatInfoController {

    @Autowired
    ProjectWeChatInfoService projectWeChatInfoService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存项目的小程序配置", description = "保存项目的小程序配置")
    @RequestMapping(value = "saveProjectWeChatInfo", method = {RequestMethod.POST})
    public ResultContent saveProjectWeChatInfo(@RequestBody @Valid ProjectWeChatInfoParam param) {
        return projectWeChatInfoService.saveProjectWeChatInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到项目的小程序配置", description = "得到项目的小程序配置")
    @RequestMapping(value = "getProjectWeChatInfo", method = {RequestMethod.POST})
    public ResultContent<ProjectWeChatInfoModel> getProjectWeChatInfo(
            @RequestBody ProjectOidParam param) {
        return projectWeChatInfoService.getProjectWeChatInfo(param.getProjectOid());
    }

    @Operation(summary = "小程序-得到小程序关联的项目oid（需要在head设置appId）", description = "得到小程序关联的项目oid")
    @RequestMapping(value = "getProjectOidForXcx", method = {RequestMethod.GET})
    public ResultContent<List<ProjectXcxModel>> getProjectOidForXcx() {
        return projectWeChatInfoService.getProjectOidForXcx();
    }

    //------------------------------feign start -----------------------
    @Operation(hidden = true, summary = "根据小程序appId得到配置", description = "根据小程序appId得到配置")
    @RequestMapping(value = "manager/getProjectWeChatInfoByAppId", method = {RequestMethod.POST})
    @Hidden
    public ResultContent<ProjectWeChatInfoModel> getProjectWeChatInfoByAppId(
            @RequestBody ProjectWxPayParam param) {
        return projectWeChatInfoService.getProjectWeChatInfoByAppId(param.getAppId());
    }

}
