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.projectAbout.ProjectAgreementConfigParam;
import com.zhongshu.card.client.model.projectAbout.ProjectCommonConfigModel;
import com.zhongshu.card.client.model.projectAbout.ProjectCommonConfigParam;
import com.zhongshu.card.server.core.service.projectAbout.ProjectCommonConfigService;
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;

/**
 * 项目的 通用设置
 *
 * @author TRX
 * @date 2024/7/26
 */
@RestController
@RequestMapping("/project/projectCommonConfig")
@Tag(name = "项目-通用设置")
public class ProjectCommonConfigController {

    @Autowired
    private ProjectCommonConfigService projectCommonConfigService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存项目的通用设置", description = "保存项目的通用设置")
    @RequestMapping(value = "saveInfo", method = {RequestMethod.POST})
    @Hidden
    public ResultContent saveInfo(@RequestBody @Valid ProjectCommonConfigParam param) {
        return projectCommonConfigService.saveInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到项目的通用配置", description = "得到项目的通用配置")
    @RequestMapping(value = "getInfo", method = {RequestMethod.POST})
    @Hidden
    public ResultContent<ProjectCommonConfigModel> getProjectWeChatInfo(@RequestBody ProjectOidParam param) {
        return projectCommonConfigService.getInfo(param.getProjectOid());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存项目的协议配置", description = "保存项目的协议配置")
    @RequestMapping(value = "saveAgreementInfo", method = {RequestMethod.POST})
    public ResultContent saveAgreementInfo(@RequestBody @Valid ProjectAgreementConfigParam param) {
        return projectCommonConfigService.saveAgreementInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "得到项目的协议配置", description = "得到项目的协议配置")
    @RequestMapping(value = "getAgreementInfo", method = {RequestMethod.POST})
    public ResultContent<ProjectAgreementConfigParam> getAgreementInfo(@RequestBody ProjectOidParam param) {
        return projectCommonConfigService.getAgreementInfo(param.getProjectOid());
    }

}
